博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu4976 A simple greedy problem.
阅读量:7038 次
发布时间:2019-06-28

本文共 2293 字,大约阅读时间需要 7 分钟。

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
#include
#include
using namespace std;const int N=1005;int T,n,cas,a[N],b[N];int f[N][N];int main(){ for(scanf("%d",&T);T--;){ scanf("%d",&n);memset(b,-1,sizeof b); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); for(int i=1;i<=n;i++){ for(int j=a[i];j;j--){ if(b[j]==-1){ b[j]=a[i];break; } } } memset(f,-1,sizeof f); f[0][0]=0; for(int i=0,t;i
=0)f[i+1][t]=max(f[i+1][t],f[i][j]+1); } } int ans=0; for(int i=0;i<=a[n];i++){ ans=max(ans,f[a[n]][i]); } printf("Case #%d: %d\n",++cas,ans); } return 0;}

 

转载于:https://www.cnblogs.com/shenben/p/6720280.html

你可能感兴趣的文章
JavaScript 作用域
查看>>
Linux Ubuntu 16.04 主机名设置
查看>>
CCNP 静态路由
查看>>
单链表二[不带头节点链表]
查看>>
Html中居中问题小结
查看>>
Spring mvc 拦截器
查看>>
MySQL GROUP BY 和GROUP_CONCAT的一些用法
查看>>
关于box2d的例子testbed
查看>>
## mysqldump 导出数据库各参数详细说明
查看>>
java中URL编码和中文相互转换
查看>>
影评:《云图》:生命并非微不足道
查看>>
hibernate4之一对一关系映射(二)
查看>>
我的友情链接
查看>>
Android第五课 编译错误分析
查看>>
Excel表格模板:教育系统清资报表下载
查看>>
VS_远程调试
查看>>
centos7修改hostname以及系统编码
查看>>
LVM配置及简介
查看>>
javascript取得浏览器地址及参数方法
查看>>
博为峰Java技术题 ——JavaSE Java实现在不同编码之间进行文件转换
查看>>