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) 最优化问题的三个解决方法都套在一个题里了,真牛逼 最优解应该是怎样的,一定存在一种最优解是先完成了耗时长的任务再干别的( ...
随机推荐
- 转:视觉中国的NoSQL之路:从MySQL到MongoDB
起因 视觉中国网站(www.chinavisual.com)是国内最大的创意人群的专业网站.2009年以前,同很多公司一样,我们的CMS和社区产品都构建于PHP+Nginx+MySQL之上:MySQL ...
- UOJ 216 Jakarta Skyscrapers
http://uoj.ac/problem/216 题意:给定A,B,C,如果集合中有数i,j(i>j),那么集合就会增加i-j这个数,问有没有在初始集合为{A,B}400步内生成C的方案. 思 ...
- ISO14443标准详细介绍
这篇文章从各方面详细介绍了ISO/IEC14443标准.第一部分:物理特性1.范围ISO/IEC14443的这一部分规定了邻近卡(PICC)的物理特性.它应用于在耦合设备附近操作的ID-1型识别卡.I ...
- SignTool.exe(签名工具)
水漂收集 -- SignTool.exe(签名工具) =============C#.Net 篇目录============== 签名工具是一个命令行工具,用于用证书对文件进行数字签名,验证文件和时间 ...
- logstash (?m) 经典例子
在和 codec/multiline 搭配使用的时候,需要注意一个问题,grok 正则和普通正则一样,默认是不支持匹配回车换行的.就像你需要 =~ //m 一样也需要单独指定,具体写法是在表达式开始位 ...
- HBase HTablePool
Instead of creating an HTable instance for every request from your client application, it makes much ...
- selenium webdriver python 环境搭建
1. 安装python https://www.python.org/getit/ 选择2.7版本,下载安装即可. 验证是否安装成功:打开cmd,输入"python -V",显示p ...
- Repo安装遇到问题
问题一: “The program 'repo' is currently not installed. You can install it by typing: sudo apt-get inst ...
- Linux 下最为人熟知的解压缩工具
很多时候,通过互联网发送或接收大文件和图片是一件令人头疼的事.压缩及解压缩工具正好可以应对这个问题.下面让我们快速浏览一些可以使得我们的工作更加轻松的开源工具. Tar Tar 由 ‘Tape arc ...
- Citrix 服务器虚拟化之十八 桌面虚拟化之部署MCS随机桌面池
Citrix 服务器虚拟化之十八 桌面虚拟化之部署MCS随机桌面池 完成桌面模版的制作后,可以开始虚拟桌面池的发布 说明: 环境基于实验十七 1.登录DC服务器创建一个组织单位名为Citrix,然后 ...