forked from oeddyo/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcha3.cpp
More file actions
57 lines (45 loc) · 923 Bytes
/
cha3.cpp
File metadata and controls
57 lines (45 loc) · 923 Bytes
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
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream fin("input.txt");
const int MAXN = 5000;
int data[MAXN];
int dp[MAXN];
int cnt = 0;
int ans = 0;
void get_dp(int end){
memset(dp,0,sizeof(dp));
dp[0] = 1;
for(int i=0; i<end; i++){
for(int j=MAXN-1; j>=0; j--){
if(j-data[i]>=0 && dp[j-data[i]]>0){
dp[j] += dp[j-data[i]];
}
}
}
//cout<<"end is "<<end;
for(int i=0; i<10; i++){
//cout<<"dp["<<i<<"] = "<<dp[i]<<endl;
}
if(dp[data[end]]){
cout<<"ok "<<data[end]<<" num = "<<dp[data[end]]<<endl;
ans+=dp[data[end]];
}
}
void work(){
for(int i=1; i<cnt; i++){
get_dp(i);
}
cout<<ans<<endl;
}
int main(){
cnt = 0;
int t;
while(fin>>t){
data[cnt++] = t;
}
cout<<"cnt is "<<cnt<<endl;
work();
return 0;
}