Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int money,dress,dp[300][300],arr[50][50];
- int wedding(int group,int money)
- {
- if(group==dress)
- return 0;
- if(dp[group][money]!=-1)
- return dp[group][money];
- int mx=-1000;
- for(int i=1;i<=arr[group][0];i++)
- {
- if(money-arr[group][i]>=0)
- mx=max(mx, wedding(group+1,money-arr[group][i])+arr[group][i]);
- }
- return dp[group][money]=mx;
- }
- int main()
- {
- int i,j,k,n,t;
- cin>>t;
- while(t--)
- {
- memset(dp,-1,sizeof(dp));
- cin>>money>>dress;
- for(i=0;i<dress;i++)
- {
- cin>>k;
- arr[i][0]=k;
- for(j=1;j<=arr[i][0];j++)
- {
- cin>>arr[i][j];
- }
- }
- int ans=wedding(0,money);
- if(ans>=0)
- cout<<ans<<endl;
- else
- cout<<"no solution"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement