some dp problems
This commit is contained in:
26
CSES - CSES Problem Set/Coin_Combinations_I.cpp
Normal file
26
CSES - CSES Problem Set/Coin_Combinations_I.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Coin Combinations I
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
const int MOD = 1e9 + 7;
|
||||
ll dp[(int)1e6 + 1];
|
||||
|
||||
int main() {
|
||||
int n; int x; cin >> n >> x;
|
||||
dp[0] = 1;
|
||||
vector<int> in(n);
|
||||
for (int i = 0; i < n; i++) cin >> in[i];
|
||||
for (int i = 0; i <= x; ++i) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (in[j] <= i) {
|
||||
dp[i] += dp[i - in[j]];
|
||||
dp[i] %= MOD;
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << dp[x] << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user