This topic is quite interesting, playing Warcraft for many people is not unfamiliar, and boss of HP are 100, people first attack, people's general attack is 1, there is so weak wood! Fortunately, the skills are their own input, or really no words.
OK, the problem is to use dynamic programming, mainly to see the state equation, the state equation is not unique, you can set F[I][J] to indicate that the second attack is the maximum damage caused by the remaining Blue J, also can set the damage J caused by the I attack the blue amount, anyway, this problem state equation is not unique, This is the first state equation I wrote, the variables a bit more, but to find the key, in fact, are clouds. State equation: F[i][j-a[k]+t]=max (f[i][j-a[k]+t],f[i-1][j]+b[k]);
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace STD;intf[101][101];intMain () {intN,t,q;inta[101],b[101];intTime while(Cin>>n>>t>>q&& (n+t+q)) {memset(f,-1,sizeof(f));//Initialize to-1 for(intI=1; i<=n; i++) {Cin>>a[i]>>b[i]; } f[0][ -]=0; a[0]=0; b[0]=1; Time= -/q;//Indicates the maximum number of rounds a person passes if( -%q!=0) time++;intans=-1; for(intI=1; i<=time; i++) { for(intj=0; j<= -; J + +)//Indicates the remaining blue amount if(f[i-1][j]!=-1) { for(intk=0; k<=n; k++)//Use skills{if(J>=a[k])//Current blue amount can support A[k] skill release, into the loop{F[i][j-a[k]+t]=max (f[i][j-a[k]+t],f[i-1][j]+b[k]);//State equation if(f[i][j-a[k]+t]>= -)//damage more than 100, the record is the first few rounds{ans=i; Break; } }if(ans!=-1) Break; } }if(ans!=-1) Break; }if(ans==-1)cout<<"My God"<<endl;Else cout<<ans<<endl; }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu-3008 Warcraft