Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int i,j,t,n,x;
- cin>>t;
- while(t--)
- {
- cin>>n;
- int coin[n];
- for(i=0;i<n;i++)cin>>coin[i];
- int w;
- cin>>w;
- int a[n][w+1];
- for(i=0;i<n;i++)
- {
- for(j=0;j<=w;j++)
- {
- if(j==0){a[i][j]=1;continue;}
- if(i==0){if(j%coin[i]==0)a[i][j]=1;
- else a[i][j]=0;
- }
- else{
- if(coin[i]>j)a[i][j]=a[i-1][j];
- else{
- a[i][j]=a[i-1][j]+a[i][j-coin[i]];
- }
- }
- }
- }
- cout<<a[i-1][j-1]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement