Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int A[100],n,cnt=0,money;
- vector<int>v;
- int dp[10][10];
- void print()
- {
- for(int i=0;i<v.size();i++) cout<<v[i]<<' ';
- cout<<"\n";
- }
- void rec(int i,int amount){
- if(i>n || amount > money)return ;
- if(amount==money)
- {
- print();
- cnt++;
- return;
- }
- v.push_back(A[i]);
- rec(i,amount+A[i]);
- v.pop_back();
- rec(i+1,amount);
- }
- int my_DP(int i,int amount)
- {
- if(i>n || amount > money)return 0;
- if(dp[i][amount]!=0)return 1;
- if(amount==money)
- {
- print();
- //cnt++;
- return 1;
- }
- v.push_back(A[i]);
- int p=my_DP(i,amount+A[i]);
- v.pop_back();
- int q=my_DP(i+1,amount);
- return dp[i][amount]=p+q;
- }
- int main()
- {
- cin>>n>>money;
- for(int i=1;i<=n;i++) cin>>A[i];
- cnt=my_DP(1,0);
- cout<<cnt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement