I actually got AC for this problem where it’s clearly mentioned that all coins are distinct integers. But it got hacked. The hack had non-distinct coins.
My code:
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, x;
cin >> n >> x;
vector <long long> v(n), dp(1000001);
for (int i = 0; i < n; ++i) cin >> v[i], dp[v[i]] = 1;
sort(v.begin(), v.end());
for (int i = 1; i <= x; ++i)
{
for (int j = 0; j < n; ++j)
{
if (v[j] > i) break;
else dp[i] += (dp[i-v[j]]), dp[i] %= mod;
}
}
cout << dp[x] << '\n';
}
Please let me know if my solution is right for distinct coins (it got accepted for the other tests). I just want a yes/no answer (please, no code).
Thanks.
//in name of THE GOD #include #include #include <string.h>
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define tinput int t; cin>>t; while(t–) #define rep(i,n) for((i)=0; (i)<(n); (i)++)
ll min(ll x, ll y) {
return (x<y)?x:y;
}