Hey there!! I am stuck in this problem for quit some time, can you guys can please help me…
It is CSES DP coin combination( CSES - Coin Combinations I ) , It results in TLE in 3 test cases.
my code:
#include<bits/stdc++.h>
using namespace std;
// #define int long long
int INF = 1e9+7;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n , m ;
cin>>n>>m;
vector<int> a(n);
for(int i = 0;i<n;i++) cin>>a[i];
vector<int> c(m+1,0);
c[0] = 1;
for(int i = 1;i<=m;i++)
for(int j = 0;j<n;j++)
{
if(i-a[j]>=0)
{
c[i]=(c[i]+c[i-a[j]])%INF;
}
}
cout<<c[m]%INF<<'\n';
return 0;
}
Your help will be appreciated.