美团笔试8.15第四题
现在在本地运行都能通过测试,不知道会不会超时和超内存,有问题可以指出来一起探讨
测试样例:5 2 2
4 2
3 3
5 4
5 3
1 5
4 2
3 3
5 4
5 3
1 5
输出:18
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int n = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int[][] arr = new int[n][2];
for(int i=0; i<n; i++) {
for(int j=0; j<2; j++) {
arr[i][j] = sc.nextInt();
}
}
findRes(arr, a, b, 0, 0, 0, 0);
System.out.println(res);
}
sc.close();
}
static int res = 0;
public static void findRes(int[][] arr, int a, int b, int ca, int cb, int sum, int index) {
if(index == arr.length) {
if(index==arr.length && ca==a && cb==b) {
res = Math.max(res, sum);
}
return;
}
findRes(arr, a, b, ca+1, cb, sum+arr[index][0], index+1);
findRes(arr, a, b, ca, cb+1, sum+arr[index][1], index+1);
findRes(arr, a, b, ca, cb, sum, index+1);
} #笔试题目##美团#


