标签:style blog http color strong os
4 12 10 7 5 1
2
解题:完全背包。。。。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 int num[60],dp[100010]; 7 int main() { 8 int n, i, m, j; 9 while(scanf("%d%d",&n,&m),n||m) { 10 for(i = 0; i < n; i++) 11 scanf("%d", &num[i]); 12 for(i = 1; i <= m; i++) 13 dp[i] = 100000; 14 dp[0] = 0; 15 for(i = 0; i < n; i++) { 16 for(j = 1; j <= m; j++) { 17 if(j >= num[i]) { 18 dp[j] = min(dp[j], dp[j-num[i]]+ 1); 19 } 20 } 21 } 22 for(i = m; i >= 0; i--) { 23 if(dp[i] != 100000) break; 24 } 25 printf("%d\n", dp[i]); 26 } 27 return 0; 28 }
标签:style blog http color strong os
原文地址:http://www.cnblogs.com/crackpotisback/p/3848497.html