Skip to content

Instantly share code, notes, and snippets.

@gbrls
Last active May 14, 2020 05:24
Show Gist options
  • Save gbrls/df699cf567a466269aace22d9acfeb1f to your computer and use it in GitHub Desktop.
Save gbrls/df699cf567a466269aace22d9acfeb1f to your computer and use it in GitHub Desktop.
kind of a solution for https://cses.fi/problemset/task/1636/
#include <stdio.h>
#define M 101
#define N 1000001
#define mod 1000000007
int n,x;
int dp[N][M]={0};
int vec[M];
int main() {
scanf("%d%d",&n,&x);
for(int i=0;i<n;i++) dp[0][i]=1;
for(int i=0;i<n;i++) scanf("%d",&vec[i]);
for(int i=1;i<=x;i++) {
for(int j=0;j<n;j++) {
long long int l = dp[i][j];
if(i>=vec[j]) l = (l+dp[i-vec[j]][j]);
if(j>0) l = (l+dp[i][j-1]);
dp[i][j] = (l%mod);
}
}
printf("%d\n",dp[x][n-1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment