标签:
import java.util.Scanner;
public class Main {
static int v;
static int n;
static int va[];
static int dp[][];
static void solve(){
for(int i=0;i<n;i++){
for(int j=0;j<=v;j++){
if(va[i]>j) dp[i+1][j]=dp[i][j];
else
dp[i+1][j]=Math.max(dp[i][j],dp[i][j-va[i]]+va[i] );
}
}
System.out.println(v-dp[n][v]);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
v=sc.nextInt();
n=sc.nextInt();
va=new int[n];
dp=new int[n+1][v+1];
for(int i=0;i<n;i++){
va[i]=sc.nextInt();
}
solve();
}
}
标签:
原文地址:http://www.cnblogs.com/watchfree/p/5769654.html