全是re怎么破?数组开大了也没用!!!
查看原帖
全是re怎么破?数组开大了也没用!!!
380737
cp13250659462楼主2020/9/3 16:05
import java.util.Scanner;

class ZXWT {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int v = sc.nextInt();
        int total = sc.nextInt();
		int[] things = new int[30];
		int[] dp = new int[20000];
        for(int i=0;i<total;i++){
        	things[i] = sc.nextInt();
        }
        for(int i=0;i<total;i++){
        	for(int j=v;j>=things[i];j--){
        		dp[j] = getMax(dp[j],dp[j-things[i]]+things[i]);
        	}
        }
        System.out.print(v-dp[v]);
	}
	
	public static int getMax(int a, int b){
		return a>b?a:b;
	}
	
}
2020/9/3 16:05
加载中...