2014多校第七场1005 || HDU 4939 Stupid Tower Defense (DP)

时间:2023-03-09 09:45:42
2014多校第七场1005  ||  HDU 4939 Stupid Tower Defense  (DP)

题目链接

题意 :长度n单位,从头走到尾,经过每个单位长度需要花费t秒,有三种塔:

红塔 :经过该塔所在单位时,每秒会受到x点伤害。

绿塔 : 经过该塔所在单位之后的每个单位长度时每秒都会经受y点伤害。

蓝塔 : 经过该塔所在单位之后,再走每个单位长度的时候时间会变成t+z。

思路 : 官方题解 :

2014多校第七场1005  ||  HDU 4939 Stupid Tower Defense  (DP)

 #include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long using namespace std ; LL dp[][] ,n,x,y,z,t,ans; int main()
{
int T ,casee = ;
scanf("%d",&T) ;
while(T--)
{
memset(dp,,sizeof(dp)) ;
scanf("%I64d %I64d %I64d %I64d %I64d",&n,&x,&y,&z,&t) ;
ans = n * t * x ;
for(int i = ; i <= n ; i ++)
{
for(int j = ; j <= i ; j++ )
{
if( !j ) dp[i][j] = dp[i-][j] + t*(i--j) * y ;
else dp[i][j] = max(dp[i-][j-]+(i-j)*y*(t+(j-)*z),dp[i-][j]+(i--j)*y*(t+j*z)) ;
ans = max(ans,dp[i][j] + (n-i)*(j * z + t)*(x+(i-j)*y)) ;
}
}
printf("Case #%d: %I64d\n",casee ++ ,ans) ;
}
return ;
}