import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int V=sc.nextInt(); int N=sc.nextInt(); int[]dp=new int[V+1]; for (int i = 0; i < N; i++) { int w=sc.nextInt(); int v=w; int s=1; for (int j = 1; j <=s; s-=j,j*=2) { for (int k = V; k >=j*w; k--) { dp[k]=Math.max(dp[k], dp[k-j*w]+j*v); } } } System.out.println(V-dp[V]); } }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题9.8 (Java代码)浏览:1636 |
ASCII帮了大忙浏览:748 |
字符串对比 (C语言代码)浏览:1398 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1144 |
【绝对值排序】 (C语言代码)浏览:820 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:919 |
【明明的随机数】 (C语言代码)浏览:785 |
【计算两点间的距离】 (C语言代码)浏览:1473 |
最小公倍数 (C语言代码)浏览:1026 |
P1000 (C语言代码)浏览:868 |