Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4939
Solution report: a line with a length of N. Three Towers can be deployed in each cell on the road to cause damage to enemies on the road, the first type of tower only causes x points of damage to enemies within the range of the tower per second, and the second type of tower causes y points of damage to enemies who have already passed the Tower per second, the third type of tower can slow down the progress of the enemy who has already passed through the tower. The specific effect is that the time of the enemy passing through a cell is t seconds. After slowing down, the time of each cell is t + Z. The deceleration effect of this tower can be superimposed, and the damage effect of the second tower can also be superimposed, each cell can have only one tower.
DP [I] [J] indicates that the first I put the green tower or blue tower, and the maximum damage to the cell I, and the recursive formula is:
DP [I] [J] = max (DP [I-1] [J] + (i-j-1) * (J * z + T) * y, DP [I-1] [J-1] + (I-j) * (J-1) * z + T) * y );
Add the next N-I damage, and the next n-I will be all placed in the first tower.
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 #define LL __int64 7 LL dp[2005][2000]; 8 9 LL n,x,y,z,t;10 11 int main()12 {13 int T,kase = 1;14 scanf("%d",&T);15 while(T--)16 {17 scanf("%I64d%I64d%I64d%I64d%I64d",&n,&x,&y,&z,&t);18 memset(dp,0,sizeof(dp));19 LL ans = n * x * t;20 for (int i = 1; i <= n; ++i)21 {22 dp[i][0] = dp[i-1][0] + t * (i - 1) * y;23 ans=max(ans,dp[i][0] + t*y*(n - i)*i + x*(n - i)*t);24 }25 for(int i = 1;i <= n;++i)26 for(int j = 1;j <= i;++j)27 if(i == j) dp[i][j] = 0;28 else dp[i][j] = max(dp[i-1][j] + (i-1-j)*y*(j*z+t),dp[i-1][j-1] + y * (i - j) * ((j-1) * z + t));29 for(int i = 1;i <= n;++i)30 for(int j = 1;j <= i;++j)31 {32 dp[i][j] += ((n-i)*x*(j * z + t) + (n-i)*(i-j)*(j*z+t)*y);33 ans = dp[i][j] > ans? dp[i][j]:ans;34 }35 printf("Case #%d: %I64d\n",kase++,ans);36 }37 return 0;38 }39 /*40 1041 4 1 1 1 142 Case #1: 943 1 3 10 3 144 Case #2: 045 3 1 10 1 346 Case #3: 7447 */View code