CSES - Shared codeLink to this code:
https://cses.fi/paste/04b6ac464bf1ec0b228547/
#include <iostream>
#include<climits>
#include <vector>
#include <unordered_map>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define endl "\n";
void bhaag_kutte(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
int mod = (int)1e9+7;
/***************************************************************************************************************/
void solve(){
int n,amount;
cin>>n>>amount;
vi coins(n);
for(int i=0;i<n;i++)cin>>coins[i];
vi dp(amount+1,0);
dp[0] = 1;
for(int i = 0;i<n;i++)
for(int x = 1;x<=amount;x++){
int c = coins[i];
if(x>=c) {
ll ans= dp[x] + dp[x-c];
ans %= mod;
dp[x] = (int)ans;
}
}
cout<<dp[amount];
}
int main(){
bhaag_kutte();
int t = 1;
// cin>>t;
while (t-->0)solve();
}