hdu4976 贪心+dp
A simple greedy problem.
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 458 Accepted Submission(s): 184

Victor and Dragon are playing DotA. Bored of normal games, Victor challenged Dragon with a competition of creep score (CS). In this competition, there are N enemy creeps for them. They hit the enemy one after another and Dragon takes his turn first. Victor uses a strong melee character so that in his turn, he will deal 1 damage to all creeps. Dragon uses a flexible ranged character and in his turn, he can choose at most one creep and deal 1 damage. If a creep take 1 damage, its health will reduce by 1. If a creep’s current health hits zero, it dies immediately and the one dealt that damage will get one score. Given the current health of each creep, Dragon wants to know the maximum CS he can get. Could you help him?
For each case, the first line contains 1 integer, N(<=1000), indicating the number of creeps. The next line contain N integers, representing the current health of each creep(<=1000).
5
1 2 3 4 5
5
5 5 5 5 5
Case #2: 2
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;
const int maxn=+;
int d[maxn];//d[i]记录血量为i的小兵有多少只
int c[maxn];//c[i]记录当前位置的小兵是由c[i]位置的小兵垫刀垫过来的
int dp[maxn][maxn];//dp[i][j]表示第i回合还剩j次补刀机会最多能杀死多少只小兵
int kase=;
int main()
{
int T;
scanf("%d",&T);
int n,x;
while(T--)
{
int ma=;
scanf("%d",&n);
memset(d,,sizeof(d));
memset(c,,sizeof(c));
memset(dp,,sizeof(dp));
for(int i=;i<n;i++)
{
scanf("%d",&x);
d[x]++;
ma=max(ma,x);
}
stack<int> q;
int num=;
for(int i=;i<=ma;i++)
{
if(d[i]==)
{
c[i]=i;
}
if(d[i]==)
{
q.push(i);
num++;
}
if(d[i]>)
{
c[i]=i;
while(!q.empty()&&d[i]>)
{
int x=q.top();
if(i-x<=num)
{
q.pop();
c[x]=i;
d[i]--;
num--;
}
else break;
}
}
}
for(int i=;i<=ma;i++)
{
for(int j=;j<=i;j++)
{
if(j>) dp[i][j]=dp[i-][j-];
if(c[i]&&j+c[i]-i<i) dp[i][j]=max(dp[i][j],dp[i-][j+c[i]-i]+);
}
}
int ans=;
for(int i=;i<=ma;i++)
{
ans=max(ans,dp[ma][i]);
}
printf("Case #%d: %d\n",++kase,ans);
}
}
hdu4976 贪心+dp的更多相关文章
- 【BZOJ-3174】拯救小矮人 贪心 + DP
3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 686 Solved: 357[Submit][Status ...
- BZOJ_3174_[Tjoi2013]拯救小矮人_贪心+DP
BZOJ_3174_[Tjoi2013]拯救小矮人_贪心+DP Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀 ...
- 洛谷P4823 拯救小矮人 [TJOI2013] 贪心+dp
正解:贪心+dp 解题报告: 传送门! 我以前好像碰到过这题的说,,,有可能是做过类似的题qwq? 首先考虑这种显然是dp?就f[i][j]:决策到了地i个人,跑了j个的最大高度,不断更新j的上限就得 ...
- 【bzoj5073】[Lydsy1710月赛]小A的咒语 后缀数组+倍增RMQ+贪心+dp
题目描述 给出 $A$ 串和 $B$ 串,从 $A$ 串中选出至多 $x$ 个互不重合的段,使得它们按照原顺序拼接后能够得到 $B$ 串.求是否可行.多组数据. $T\le 10$ ,$|A|,|B| ...
- 【bzoj3174】[Tjoi2013]拯救小矮人 贪心+dp
题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚 ...
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- 贪心+DP【洛谷P4823】 [TJOI2013]拯救小矮人
P4823 [TJOI2013]拯救小矮人 题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以 ...
- 贪心+dp
贪心+dp 好多题都是这个思想, 可以说是非常重要了 思想一: 在不确定序列无法dp的情况下, 我们不妨先假设序列已经选定, 而利用贪心使序列达到最优解, 从而先进行贪心排序, 在进行dp选出序列 思 ...
- 【题解】CF1056F Write the Contest(三分+贪心+DP)
[题解]CF1056F Write the Contest(三分+贪心+DP) 最优化问题的三个解决方法都套在一个题里了,真牛逼 最优解应该是怎样的,一定存在一种最优解是先完成了耗时长的任务再干别的( ...
随机推荐
- 反射-b
Class pkClass=NSClassFromString(@"PKAddPassesViewController"); if (pkClass) { NS ...
- COS访谈第十八期:陈天奇
COS访谈第十八期:陈天奇 [COS编辑部按] 受访者:陈天奇 采访者:何通 编辑:王小宁 简介:陈天奇,华盛顿大学计算机系博士生,研究方向为大规模机器学习.他曾获得KDD CUP 20 ...
- [转]Windows平台下安装Hadoop
1.安装JDK1.6或更高版本 官网下载JDK,安装时注意,最好不要安装到带有空格的路径名下,例如:Programe Files,否则在配置Hadoop的配置文件时会找不到JDK(按相关说法,配置文件 ...
- MD3200扩展柜MD1200,玩起
杀到最后一关了,希望能让IOFENCE,IMPI之类的概念弄好. 至于ISCSI,CLVM,NAS,NFS,SAN这些东东的性能,我总觉得不如DAS,HBA卡直接到共享存储快.其它方案,不都灵活一点, ...
- BZOJ1524: [POI2006]Pal
1524: [POI2006]Pal Time Limit: 5 Sec Memory Limit: 357 MBSubmit: 308 Solved: 101[Submit][Status] D ...
- at命令
在windows系统中,windows提供了计划任务这一功能,在控制面板 -> 性能与维护 -> 任务计划, 它的功能就是安排自动运行的任务. 通过'添加任务计划'的一步步引导,则可建立一 ...
- Socket的协议地址属性
首先列举所需要的头文件 #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #in ...
- LoadRunner基础入门教程
原文地址:http://jingyan.baidu.com/article/215817f7dedfb01eda1423df.html 从LoadRunner英语字面上进行理解就是负载跑步者,为什么这 ...
- DatabaseMetaData的用法【转载】
一 . 得到这个对象的实例Connection con ;con = DriverManager.getConnection(url,userName,password);DatabaseMetaDa ...
- HDU5409---CRB and Graph 2015多校 双联通分量缩点
题意:一个联通的无向图, 对于每一条边, 若删除该边后存在两点不可达,则输出这两个点, 如果存在多个则输出第一个点尽可能大,第二个点尽可能小的. 不存在输出0 0 首先 若删除某一条边后存在多个联通分 ...