Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3623.
Meaning: Give N types of ships that can be built and the opposite tower life value L, each ship gives the construction time t [I] and the output per second DPS [I], the dock can only build one ship at a time (similar to the Red Police) and ask how long it will take to destroy the tower.
Thought: DP [I] represents the amount of damage that could be caused in the previous I seconds. It reversely considers the time for the construction of each ship, the construction time used in the previous I seconds is ~ I second, the state transition equation is DP [I + T [J] = max (DP [I + T [J], DP [I] + DPS [J] * I), because the construction time of the ship is ~ T [I] + 1 ~ So there will be no overlapping construction time during status transfer.
P.s. The game was no longer witty. I understood the each time in this question as a second to create a new ship.
Code:
#include <algorithm>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#include <ctype.h>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define eps 1e-8#define INF 0x7fffffff#define maxn 10005#define PI acos(-1.0)#define seed 31//131,1313typedef long long LL;typedef unsigned long long ULL;using namespace std;int t[35],dps[35];int dp[355];int main(){ int N,L; while(~scanf("%d%d",&N,&L)) { memset(dp,0,sizeof(dp)); for(int i=0;i<N;i++) scanf("%d%d",&t[i],&dps[i]); for(int i=0;i<=L+20;i++) for(int j=0;j<N;j++) dp[i+t[j]]=max(dp[i+t[j]],dp[i]+dps[j]*i); for(int i=0;i<=L+20;i++) if(dp[i]>=L) { printf("%d\n",i); break; } } return 0;}
Zoj 3623 battle ships simple DP