CSES - Shared codeLink to this code:
https://cses.fi/paste/c0e3ad19fd184ec3227a11/
#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 FIO(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
/***************************************************************************************************************/
int mod = (int)1e9+7;
void solve(vi coins, int n, int amount){
vll 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) {
dp[x] += dp[x - c];
dp[x] %= mod;
}
}
cout<<dp[amount];
}
int main(){
FIO();
int n ,k;
cin>>n>>k;
vi coins(n);
for(int i=0;i<n;i++)cin>>coins[i];
solve(coins,n,k);
}