-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN9084.cpp
37 lines (33 loc) · 883 Bytes
/
N9084.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
# include<stdio.h>
# include<vector>
using namespace std;
vector<int> coinVec;
vector<vector<int> >DP;
int getAns(int,int);
int main(){
int testCase,num,coin,money,possibleCase;
scanf("%d",&testCase);
while(testCase--){
scanf("%d",&num);
coinVec.assign(num,0);
for(int i = 0; i<num;i++){
scanf("%d",&coin);
coinVec[i] = coin;
}
scanf("%d",&money);
DP.assign(num,vector<int>(money+1,-1));
possibleCase = getAns(money,num-1);
printf("%d\n",possibleCase);
}
return 0;
}
int getAns(int money,int coin){
if (money < 0 || coin < 0)
return 0;
if (money == 0 && coin == 0)
return 1;
if (DP[coin][money] != -1)
return DP[coin][money];
DP[coin][money] = getAns(money,coin-1) + getAns(money - coinVec[coin], coin);
return DP[coin][money];
}