递归解法:
public class Main0 {
static int n = 5;
static int[] v={0,3,7,4,49,2};
static int[] w={0,3,4,7,50,2};
public static void main(String[] args){
int AV = 10;
int BV = 50;
System.out.println(get(1,AV,BV));
}
public static int get(int i,int AV, int BV){
if(i==n)if(AV>=v[n]||BV>=v[n])return w[n];
else return 0;
int res = 0;
if(v[i]<=AV) res = Math.max(get(i+1,AV-v[i],BV)+w[i],res);
if(v[i]<=BV) res = Math.max(get(i+1,0,BV-v[i])+w[i],res);
res = Math.max(get(i+1,AV,BV),res);
return res;
}
}
二维数组解法:
public class Main{
static int n = 5;
static int[] v = {0,3,7,4,49,2};
static int[] w = {0,3,4,