HDU 4939 Stupid Tower Defense(贪心+动态规划)
2015-11-08 19:00
603 查看
可以发现对于最优解红塔一定是放在最后的。对于蓝塔和绿塔进行dp,dp[i][j]表示在长度为n的路径上已经安放i个绿塔和j个蓝塔可造成的最大伤害,然后进行转移。最优解一定是路径上放满了塔,这样n-i-j得到的就是红塔的数量,这样比较得到最大值即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int maxn=1505;
LL dp[maxn][maxn];
int main()
{
int T,kase=0;
scanf("%d",&T);
while(T--)
{
int n;
LL x,y,z,t;
scanf("%d%I64d%I64d%I64d%I64d",&n,&x,&y,&z,&t);
memset(dp,0,sizeof(dp));
LL ans=0;
for(int i=0; i<=n; ++i)
{
for(int j=0; i+j<=n; ++j)
{
int l=n-i-j-1;
dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(t+j*z)*y*l);
dp[i][j+1]=max(dp[i][j+1],dp[i][j]+i*y*z*l);
}
}
for(int i=0; i<=n; ++i)
{
for(int j=0; i+j<=n; ++j)
{
int l=n-i-j;
ans=max(ans,dp[i][j]+x*l*(t+j*z));
}
}
printf("Case #%d: %I64d\n",++kase,ans);
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int maxn=1505;
LL dp[maxn][maxn];
int main()
{
int T,kase=0;
scanf("%d",&T);
while(T--)
{
int n;
LL x,y,z,t;
scanf("%d%I64d%I64d%I64d%I64d",&n,&x,&y,&z,&t);
memset(dp,0,sizeof(dp));
LL ans=0;
for(int i=0; i<=n; ++i)
{
for(int j=0; i+j<=n; ++j)
{
int l=n-i-j-1;
dp[i+1][j]=max(dp[i+1][j],dp[i][j]+(t+j*z)*y*l);
dp[i][j+1]=max(dp[i][j+1],dp[i][j]+i*y*z*l);
}
}
for(int i=0; i<=n; ++i)
{
for(int j=0; i+j<=n; ++j)
{
int l=n-i-j;
ans=max(ans,dp[i][j]+x*l*(t+j*z));
}
}
printf("Case #%d: %I64d\n",++kase,ans);
}
return 0;
}
相关文章推荐
- C++动态规划之最长公子序列实例
- C++动态规划之背包问题解决方法
- C#使用动态规划解决0-1背包问题实例分析
- 动态规划
- C++ 动态规划
- DP(动态规划) 解游轮费用问题
- 动态规划的用法——01背包问题
- 动态规划的用法——01背包问题
- 《收集苹果》 动态规划入门
- 《DNA比对》蓝桥杯复赛试题
- 《背包问题》 动态规划
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 关于爬楼梯的动态规划算法
- 动态规划 --- hdu 1003 **
- DP问题各种模型的状态转移方程
- 0-1背包解题过程
- 背包问题
- USACO 3.2.2:Stringsobits
- 字符串编辑距离
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)