标签:style io os ar for sp art on amp
One of our best friends is getting married and we allno solution
dp[i][j]表示已经买了i种花费j
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<limits.h> typedef long long LL; using namespace std; int dp[25][220]; int k[25],pri[25][25]; int m,c; int main() { int t; cin>>t; while(t--) { cin>>m>>c; for(int i=1;i<=c;i++) { cin>>k[i]; for(int j=1;j<=k[i];j++) cin>>pri[i][j]; } memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=1;i<=c;i++) { for(int j=0;j<=m;j++) { if(dp[i-1][j]) { for(int kk=1;kk<=k[i];kk++) { if(j+pri[i][kk]<=m) dp[i][j+pri[i][kk]]=1; } } } } int flag=1; for(int i=m;i>=0;i--) { if(dp[c][i]) { cout<<i<<endl; flag=0; break; } } if(flag) cout<<"no solution"<<endl; } return 0; }
UVA 11450 Wedding shopping(DP)
标签:style io os ar for sp art on amp
原文地址:http://blog.csdn.net/u013582254/article/details/39942023