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

Problem Description

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?
 
Input
The first line of input contains only one integer T(<=70), the number of test cases.

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).

 
Output
Each output should occupy one line. Each line should start with "Case #i: ", with i implying the case number. For each case, just output the maximum CS Dragon can get.
 
Sample Input
2
5
1 2 3 4 5
5
5 5 5 5 5
 
Sample Output
Case #1: 5
Case #2: 2
 
Author
BJTU
 
Source
 

#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.的更多相关文章

  1. hdu4976 A simple greedy problem. (贪心+DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4976 2014 Multi-University Training Contest 10 1006 A simp ...

  2. HDU 4976 A simple greedy problem. 贪心+DP

    题意: 给定n<=1000个小兵,A每次都能使小兵掉1点血,B每次能使所有小兵掉1点血,A.B轮流攻击,每次轮到A他会选择是否攻击,轮到B必须攻击.求A最多能杀死多少小兵.(当小兵血量为1时被攻 ...

  3. A simple greedy problem(hdu 4976)

    题意:有n个小兵,每个小兵有a[i]血量,第一个人每次只能对一个小兵砍一滴血,第二个人每次对所有生存的小兵砍一滴血. 最后看第一个人最多可以砍杀几个小兵. /* 首先,如果所有小兵的血量都不同的话,我 ...

  4. BNU 28887——A Simple Tree Problem——————【将多子树转化成线段树+区间更新】

    A Simple Tree Problem Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on ZJU. O ...

  5. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  6. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  7. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. CentOS安装redmine 2后的简单配置

    CentOS5.4安装redmine详细步骤 http://blog.csdn.net/leekwen/article/details/8516832 <<<<输出日志的配置& ...

  2. Linux下DedeCMS详细安全设置

    经常会听到使用dedecms的站长抱怨,网站又被挂马了,dedecms真的很不安全.dedecms可能存在某些漏洞这不假,但主要责任真的是dedecms吗?我们知道,一个黑客想上传木马,首先得可以找到 ...

  3. cs108 04 oop design

    oop design 分为以下几个方面: - encapsulation and modularity(封装和模块化) - API/Client interface design(API 接口给调用类 ...

  4. html精灵技术(用来显示图片的某个区域)

    .left .left_down li.a.left-down-pic{display:block;width:50px;height:50px;background:url(images/app_i ...

  5. 最大似然估计 (MLE)与 最大后验概率(MAP)在机器学习中的应用

    最大似然估计 MLE 给定一堆数据,假如我们知道它是从某一种分布中随机取出来的,可是我们并不知道这个分布具体的参,即“模型已定,参数未知”. 例如,对于线性回归,我们假定样本是服从正态分布,但是不知道 ...

  6. 15 款优化表单的 jQuery 插件

    网页上的表单提供给用户的一种交互的方式,用户输入数据,提交到服务器,等待后续的处理.这些表单在我们浏览的网页中随处可见,也容易被我们忽略. 比如,“联系我们”页面会提供一个表单给用户填写他们的信息和想 ...

  7. 自然语言交流系统 phxnet团队 创新实训 项目博客 (二)

    基本要求 打开软件,即可进入2D文本交流界面, 软件此时已经连接到服务器,点击文本输入框输入你想说的话,点击发送按钮即可进行交流,点击CHAT和STUDY分别切换到聊天模式或是学习模式,聊天模式是机器 ...

  8. Java泛型函数的运行时类型检查的问题

    在一个数据持久化处理中定义了数据保存和读取的 泛型函数的,但是在运行时出现类型转换错误,类型不匹配,出错的位置不是load方法,而是在调用load方法之后,得到了列表数据,对列表数据进行使用时出现的. ...

  9. 学习 TList 类的实现[7]

    总结目前 TMyList 已具备的功能(3 个方法.3 个属性): Add: 添加; Delete: 删除; Clear: 清空;Count: 元素总数;Capacity: 已存在的所有元素位置数;L ...

  10. 使用 C# 开发智能手机软件:推箱子(二)

    在上篇文章"使用 C# 开发智能手机软件:推箱子(一)"中.我对推箱子程序作了整体介绍.这次,我先介绍 Common/Fcl.cs 源程序文件.  1 using System; ...