标签:des style blog http io color os ar java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8143 Accepted Submission(s): 3796
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define max(a,b) ((a)>(b)?(a):(b)) #define N 110 int e,r,n,t; //经验值,忍耐度,种类,上限 int dp[N][N]; //dp[j][k]表示用j点忍耐度,杀k只怪的最大经验值 int ei[N],rd[N]; //增加的经验值,减去的忍耐度 int main() { int i,j,k; while(scanf("%d%d%d%d",&e,&r,&n,&t)!=EOF) { memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { scanf("%d%d",&ei[i],&rd[i]); } for(i=1;i<=n;i++) { for(j=rd[i];j<=r;j++) { for(k=1;k<=t;k++) { dp[j][k]=max(dp[j][k],dp[j-rd[i]][k-1]+ei[i]); } } } if(dp[r][t]<e) cout<<-1<<endl; else { for(i=r;;i--) { if(dp[i][t]<e) break; } cout<<r-(i+1)<<endl; } } return 0; }
标签:des style blog http io color os ar java
原文地址:http://www.cnblogs.com/hate13/p/4056234.html