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语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:543 |
A+B for Input-Output Practice (III) (C语言代码)浏览:569 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:578 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1143 |
用筛法求之N内的素数。 (C++代码)浏览:692 |
1113题解浏览:784 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:556 |
找出最长的字符串来 (C语言代码)浏览:1762 |
数列有序 (C语言代码)浏览:930 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:525 |