Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bismillahir Rahman-ir Rahim
- #include <bits/stdc++.h>
- using namespace std;
- #define debug(x) cout << '>' << #x << " : " << x << endl;
- #define all(c) c.begin(), c.end()
- #define F first
- #define S second
- #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- typedef unsigned long long ull;
- typedef long long ll;
- vector < int > coins;
- int n;
- const int mod = 1e9+7;
- int dp[105][1000000];
- int ways(int i, int sum){
- if(sum < 0) return 0;
- if(sum == 0) return 1;
- if(sum != 0 and i <= 0){
- return 0;
- }
- if(dp[i][sum] != -1) return dp[i][sum];
- return dp[i][sum] = ((ways(i-1, sum) % mod) + (ways(i, sum - coins[i-1]) % mod)) % mod;
- }
- int main(){
- memset(dp, -1, sizeof dp);
- int x;
- cin >> n >> x;
- for(int i = 0; i < n; i++){
- int c;
- cin >> c;
- coins.push_back(c);
- }
- cout << ways(n, x) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement