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