标签:
这里就只放自己刷的题目了,毕竟是弱弱哒
1 #include <algorithm> 2 #include <cstdio> 3 4 using namespace std; 5 6 int main() 7 { 8 int n,m; 9 while (~scanf("%d", &n), n) 10 { 11 int f[2013] = {0}, menu[2013] = {0}; 12 for (int i = 1; i <= n; ++i){ 13 scanf("%d",&menu[i]); 14 } 15 16 sort(menu + 1, menu + 1 + n); 17 int tmp1 = menu[n]; 18 scanf("%d",&m); 19 if (m < 5){ 20 printf("%d\n",m); 21 continue; 22 } 23 m -= 5; 24 25 for (int i = 1; i < n; ++i){ 26 for (int v = m; v >= menu[i]; --v){ 27 if (f[v] < f[v - menu[i]] + menu[i]){ 28 f[v] = f[v - menu[i]] + menu[i]; 29 } 30 } 31 } 32 printf("%d\n",m + 5 - tmp1 - f[m]); 33 } 34 35 return 0; 36 }
万恶的题目啊!第一道01背包的水题,然后因为sort中的"+ n + 1"写成了"+ n"让我debug了半个钟头有木有!!!!阿西吧!
标签:
原文地址:http://www.cnblogs.com/comma-01/p/5357130.html