首页 / 腾讯笔试
#
腾讯笔试
#103743次浏览 1137人互动
此刻你想和大家分享什么
腾讯2022实习生笔试情况与题解
牛客ID280561...:第五题来不及做,用深搜能过70%,提示超时了😂
import java.util.Scanner;
public class Main {
static int max = Integer.MIN_VALUE;
public static void dfs(int[] price, int day, int money, int count){
if(money < 0)
return;
if(count < 0)
return;
if(day == price.length-1){
max = Math.max(max, money+count*price[price.length-1]);
return;
}
//买股票
dfs(price, day+1, money-price[day], count+1);
//卖股票
dfs(price, day+1, money+price[day], count-1);
dfs(price, day+1, money, count);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] price = new int[n];
for (int i = 0; i < n; i++) {
price[i] = sc.nextInt();
}
dfs(price, 0, m, 0);
System.out.println(max);
}
}

点赞 评论 收藏
分享
2024-04-03 21:57
西安电子科技大学 前端工程师 点赞 评论 收藏
分享
腾讯0424开发岗笔试题代码
heychong:不明白了,第一题我也是这样写的循环,也是str[j].charAt(i) ,一直说我这里数组越界,本地IDE都没问题

点赞 评论 收藏
分享
腾讯2023产品经理培训生综合素质测评
李一一一:救命
这测评内容也太多了叭,我收到链接都不想做了

点赞 评论 收藏
分享
腾讯9.5笔试
xidian_mao:AK贴
https://www.cnblogs.com/xidian-mao/p/15231379.html

点赞 评论 收藏
分享
点赞 评论 收藏
分享