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) 最优化问题的三个解决方法都套在一个题里了,真牛逼 最优解应该是怎样的,一定存在一种最优解是先完成了耗时长的任务再干别的( ...
随机推荐
- IOS--UIActivityIndicatorView的使用方法详细
IOS--UIActivityIndicatorView的使用方法详细 // UIActivityIndicatorView的常用方法 活动指示器,就是旋转进度轮 UIActivityIndica ...
- 转:微博CacheService架构浅析
文章来自于:http://www.infoq.com/cn/articles/weibo-cacheservice-architecture 微博作为国内最大的社交媒体网站之一,每天承载着亿万用户的服 ...
- win2k,XP下用setupapi.dll自动安装Driver
win2k,XP下用setupapi.dll自动安装Driver 在驱网看到54cndr 写的这篇文章,虽然自己一直都用Installshield,但还是觉得这个也是一个很好的思路,故摘录在此. 用s ...
- 关于Qt在子线程中使用QMessageBox的折衷方法
Qt将所有GUI相关的处理都限制在主线程中,这么做有助于防止意想不到的访问冲突产生,但也限制了线程中某些简单的UI交互的实现,比如QMessageBox. 因为QMessageBox必须在主线程中打开 ...
- java实现DES加密与解密,md5加密
很多时候要对秘要进行持久化加密,此时的加密采用md5.采用对称加密的时候就采用DES方法了 import java.io.IOException; import java.security.Messa ...
- Excel进行项目规划的好处
1.表格的方式 2.多个工作表 3.插入图片 4.清晰的规划 5.大众都能看得懂 6.辅助一些数据表设计,其他的流程设计 7.对项目该做什么,进度等等有一个明确的认识 8.项目管理,吃透需求,对进度把 ...
- 透过Extjs学习JavaScript---闭包篇
目录 一.前言 二.基础讲解 三.知识应用 四.总结 五.常见问题 一.前言 JavaScript设计得最出色的就是它的函数的实现,它几乎接近于完美.我们现在现就来介绍它其中一个功能“闭包”.我们可以 ...
- 4Sum——LeetCode
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- HDU_1846——最简单的巴什博弈
Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中 ...
- jvm之内存分配与回收策略
1.java堆中各代分布 (1)Young:主要是用来存放新生的对象. (2)Old:主要存放应用程序中生命周期长的内存对象. (3)Permanent:是指内存的永久保存区域,主要存放Class和M ...