CSES Solutions
#1635Dynamic Programming

Coin Combinations I

View on CSES

Solution

1635-Coin_Combinations_I.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4constexpr int M=1e9+7;
5signed main(){
6  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
7  int n,x; cin>>n>>x;
8  int a[n]; for(int i=0;i<n;++i) cin>>a[i];
9  int dp[x+1]; dp[0]=1;
10  for(int i=1;i<=x;++i){
11    dp[i]=0;
12    for(int j=0;j<n;++j){
13      if(a[j]<=i){
14        dp[i]+=dp[i-a[j]],
15        dp[i]%=M;
16      }
17    }
18  }
19  cout<<dp[x]%M<<'\n';
20  return 0;
21}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.