hdu4976 A simple greedy problem.
A simple greedy problem.
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 476 Accepted Submission(s): 193

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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int T,n,cas,a[N],b[N];
int f[N][N];
int main(){
for(scanf("%d",&T);T--;){
scanf("%d",&n);memset(b,-,sizeof b);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i=;i<=n;i++){
for(int j=a[i];j;j--){
if(b[j]==-){
b[j]=a[i];break;
}
}
}
memset(f,-,sizeof f);
f[][]=;
for(int i=,t;i<a[n];i++){
for(int j=;j<=i+;j++){
f[i+][j+]=f[i][j];
if((~b[i+])&&(t=j-b[i+]+i+)>=)f[i+][t]=max(f[i+][t],f[i][j]+);
}
}
int ans=;
for(int i=;i<=a[n];i++){
ans=max(ans,f[a[n]][i]);
}
printf("Case #%d: %d\n",++cas,ans);
}
return ;
}
hdu4976 A simple greedy problem.的更多相关文章
- hdu4976 A simple greedy problem. (贪心+DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4976 2014 Multi-University Training Contest 10 1006 A simp ...
- HDU 4976 A simple greedy problem. 贪心+DP
题意: 给定n<=1000个小兵,A每次都能使小兵掉1点血,B每次能使所有小兵掉1点血,A.B轮流攻击,每次轮到A他会选择是否攻击,轮到B必须攻击.求A最多能杀死多少小兵.(当小兵血量为1时被攻 ...
- A simple greedy problem(hdu 4976)
题意:有n个小兵,每个小兵有a[i]血量,第一个人每次只能对一个小兵砍一滴血,第二个人每次对所有生存的小兵砍一滴血. 最后看第一个人最多可以砍杀几个小兵. /* 首先,如果所有小兵的血量都不同的话,我 ...
- BNU 28887——A Simple Tree Problem——————【将多子树转化成线段树+区间更新】
A Simple Tree Problem Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on ZJU. O ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- Java学习理解路线图
信息来自知乎网友 学习截图:来自开源力量
- hadoop的调试
折腾hadoop的调试很久了,一直都没折腾对,查过很多资料,但是都没试出来,最终在不断地尝试当中调试出来了,所以想把这个过程记录下来,和大家分享一下. 调试分为两部分,MapReduce的调试和源码的 ...
- mysql 授权的时候库名不能添加单引号homestead.* 写成 '库名'.* 错的语法
create user 'wechat'@'192.168.10.%' identified by 'xxxxx'; create database 库名DEFAULT CHARSET utf8 CO ...
- HTTP协议详解(文档)
目录引言................................................................................................ ...
- CSS边框-属性详解
图解CSS padding.margin.border属性 W3C组织建议把所有网页上的对像都放在一个盒(box)中,设计师可以通过创建定义来控制这个盒的属性,这些对像包括段落.列表.标题.图片以及层 ...
- 关于Unity中的NGUI和UGUI
一.用Unity开发2D游戏,有三套关系 1.GUI:Unity本身自带的GUI 2.NGUI:以前在Unity中广泛来做2D的,是第三方的包,需要安装 3.UGUI:Unity5.X后(其实是Uni ...
- if、for、while、do 等语句自占一行
if.for.while.do 等语句自占一行,执行语句不得紧跟其后.不论 执行语句有多少都要加{}.这样可以防止书写失误. #include <iostream> /* run this ...
- YUV数据YUY2到I420
/* 主要的采样格式有YCbCr 4:2:0.YCbCr 4:2:2.YCbCr 4:1:1和 YCbCr 4:4:4.其中YCbCr 4:1:1 比较常用,其含义为:每个点保存一个 8bit 的亮度 ...
- 在 Mac 上搭建 Nginx PHP Mysql 开发环境
事实上这个过程跟Linux下安装都几乎相同,仅仅是部分命令有区别,大同小异. 网上看到非常多教程都是用 brew 之类的包管理器安装,可是 Mac 自带了 php , 难道还要再装一个第三方的?强迫症 ...
- jquery widgets 弹框
<div id='dialog' style="display:none;"> <div style="text-align:center;" ...