Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define neg -1000000
- using namespace std;
- int dp[203][23],price[23][23],M,C;
- int wedding_shopping(int money,int garment)
- {
- if(money<0) return neg;
- if(garment==C) return M-money;
- if(dp[money][garment]!=-1)
- return dp[money][garment];
- int ans = -1;
- for(int model=1; model<=price[garment][0]; model++)
- {
- ans = max(ans,wedding_shopping(money-price[garment][model],garment+1));
- }
- return dp[money][garment] = ans;
- }
- int main()
- {
- int test,i,j,result;
- scanf("%d",&test);
- while(test--)
- {
- scanf("%d%d",&M,&C);
- for(i=0; i<C; i++)
- {
- scanf("%d",&price[i][0]);
- for(j=1; j<=price[i][0]; j++)
- {
- scanf("%d",&price[i][j]);
- }
- }
- memset(dp,-1,sizeof(dp));
- result = wedding_shopping(M,0);
- if(result<0)
- {
- printf("no solution\n");
- }
- else
- {
- printf("%d\n",result);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment