CSES - Shared codeLink to this code:
https://cses.fi/paste/788adda2797b2a1c9ab37a/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long MOD = 1e9 + 7;
void solve(int t)
{
int n, x;
cin >> n >> x;
vector<int> c(n);
vector<int> DP(x + 1, 0);
DP[0] = 1;
for (int i = 0; i < n; i++)
{
cin >> c[i];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= x; j++)
{
if ((j - c[i]) >= 0)
{
DP[j] = (DP[j - c[i]] + DP[j]) % MOD;
}
}
}
cout << DP[x];
return;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--)
{
solve(t);
}
return 0;
}