-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9084.cpp
More file actions
46 lines (33 loc) · 876 Bytes
/
9084.cpp
File metadata and controls
46 lines (33 loc) · 876 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
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include <string>
using namespace std;
int N, M;
int arr[21];
int dp[21][10001];
int coin(int idx, int nowVal) {
if (idx == N) {
if (nowVal == 0)return 1;
else return 0;
}
if (dp[idx][nowVal] != -1)return dp[idx][nowVal];
int val = 0;
for (int i = 0; i < 10001; i++) {
if (nowVal - arr[idx] * i >= 0)val += coin(idx + 1, nowVal - arr[idx] * i);
else break;
}
return dp[idx][nowVal] = val;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int T; cin >> T;
while (T--) {
fill(&dp[0][0], &dp[20][10001], -1);
cin >> N;
for (int i = 0; i < N; i++)cin >> arr[i];
cin >> M;
cout << coin(0, M)<<'\n';
}
}