Skip to content

Commit 1f740a6

Browse files
authoredSep 22, 2018
dp
1 parent 0b40abb commit 1f740a6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
 

‎SWEA/3752.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//dp
2+
3+
#include <stdio.h>
4+
#include <memory.h>
5+
#include <vector>
6+
using namespace std;
7+
bool d[10001][101];
8+
int visit[10001][101];
9+
int pt[101];
10+
int cnt[101];
11+
int tc;
12+
vector<int> card;
13+
bool test(int p,int cix){
14+
if (p == 0) return true;
15+
else if (p < 0 || cix<0) return false;
16+
if (visit[p][cix] == tc) return d[p][cix];
17+
visit[p][cix] = tc;
18+
19+
d[p][cix] = false;
20+
for (int i = 0; i <= cnt[card[cix]] && !d[p][cix]; i++) d[p][cix] |= test(p - i*card[cix], cix - 1);
21+
22+
return d[p][cix];
23+
24+
}
25+
int main(){
26+
int i;
27+
int T;
28+
int N;
29+
for (scanf("%d", &T), tc = 1; tc <= T; tc++){
30+
memset(d, 0, sizeof(d));
31+
memset(cnt, 0, sizeof(cnt));
32+
card.clear();
33+
int tot = 0;
34+
int mx = 0;
35+
int mn = 101;
36+
int ans = 1;
37+
for (scanf("%d", &N), i = 0; i < N; i++){
38+
scanf("%d",pt+i);
39+
tot += pt[i];
40+
cnt[pt[i]]++;
41+
if (mx < pt[i]) mx = pt[i];
42+
if (mn > pt[i]) mn = pt[i];
43+
}
44+
for (i = mn; i <= mx; ++i){
45+
if (cnt[i]) card.push_back(i);
46+
}
47+
for (; tot>=mn; --tot) ans += test(tot, card.size()-1);
48+
printf("#%d %d\n",tc,ans);
49+
}
50+
51+
return 0;
52+
}

0 commit comments

Comments
 (0)
Please sign in to comment.