Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- const int MOD = 1e9 + 7;
- int arr[100+1];
- int n;
- int dp[101][1000001];
- int rec(int i, int a)
- {
- int sum=0;
- if(dp[i][a] != -1) {
- return dp[i][a];
- }
- if (a==0)
- {
- return 1;
- }
- if (a-arr[i]>=0)
- {
- sum+=rec(i, a-arr[i]);
- if(sum >= MOD) {
- sum -= MOD;
- }
- }
- if (i+1<n)
- {
- sum+=rec(i+1, a);
- if(sum >= MOD) {
- sum -= MOD;
- }
- }
- dp[i][a] = sum;
- return sum;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- int x;
- cin>>n>>x;
- for (int i=0;i<n;i++)
- {
- cin>>arr[i];
- }
- // sort (arr, arr+n);
- for(int i = 0; i < n; ++i) {
- for(int j = 0; j <= x; ++j) {
- dp[i][j] = -1;
- }
- }
- cout<<rec(0,x)<<endl;
- return 0;
- }
- //869167734
- //869167734
Advertisement
Add Comment
Please, Sign In to add comment