hdu2159完全背包
md心里有事的时候不能写题操
FATE
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13285 Accepted Submission(s):
6292
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n,m,s,a,b,i,j,k;
int dp[105][105]; //dp[i][j] 忍耐度为i,杀j个怪得到的最大经验
while(cin>>n>>m>>k>>s){
memset(dp,0,sizeof(dp));
for(i=1;i<=k;++i){
cin>>a>>b;
for(j=b;j<=m;++j)
for(int ti=1;ti<=s;ti++)
dp[j][ti]=max(dp[j][ti],dp[j-b][ti-1]+a);
}int sb=-1;
//cout<<n<<" "<<m<<endl;
for(i=1;i<=m;++i){
for(j=1;j<=s;++j)
if(dp[i][j]>=n) {sb=m-i;break;} //一直把这个几把break当成直接跳出两个for无限脑短路操操操!!!
if(sb!=-1) break;
}
cout<<sb<<endl;
}
return 0;
}
静不下心= =