-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path1014.cpp
59 lines (48 loc) · 978 Bytes
/
1014.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
bool dp[30][20000];
int main() {
int v;
cin >> v;
int n;
cin >> n;
//int **dp =new int[n];
vector<int> th;
for(int i=0; i<n; i++) {
int a;
cin >> a;
th.push_back(a);
}
//sort(th.begin(), th.end());
for(int i=0; i<n+1; i++) {
dp[i][0]=true;
}
// for(int j=0; j<v+1; j++) {
// dp[0][j]=0;
// }
for(int i=0; i<n; i++) {
for(int j=0; j<v; j++) {
dp[i+1][j+1]=false;
if(j+1-th[i]>=0)
dp[i+1][j+1]=dp[i][j+1]||dp[i+1][j+1-th[i]];
else
dp[i+1][j+1]=dp[i][j+1];
}
}
int maxv=0;
for(int j=v; j>=0; j--) {
if(dp[n][j]) {
maxv=j;
break;
}
}
cout << v-maxv;
return 0;
}