我提交一份代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 |
#include <iostream>#include <cstdio>#include <algorithm>#include <cstdlib>using
namespace std;int main(){ int
s, n; int
price[2048]; while(cin >> s >> n) { int
dp[2048] = {0}; for
(int i = 1; i <= n; i++) cin >> price[i]; for
(int i = 1; i <= n; i++) for
(int v = s; v >= price[i]; v--) dp[v] = max(dp[v], dp[v - price[i]] + price[i]); cout << dp[s] << endl; } return
0;} |
原文地址:http://www.cnblogs.com/alogfans/p/3730253.html