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 ...
随机推荐
- Tomcat (1) —— Mac下配置Tomcat Https/SSL
Tomcat (1) -- Mac下配置Tomcat Https/SSL tomcat版本: tomcat-8.0.29 jdk版本: jdk1.8.0_65 参考来源: SSL/TLS Config ...
- ZooKeeper源码分析:Quorum请求的整个流程(转)
Quorum请求是转发给Leader处理,并且需要得一个Follower Quorum确认的请求.这些请求包括: 1)znode的写操作(OpCode.create,OpCode.delete,OpC ...
- 重复数据删除 开源实现 (deduputil) (转)
[dedup util] dedup util是一款开源的轻量级文件打包工具,它基于块级的重复数据删除技术,可以有效缩减数据容量,节省用户存储空间.目前已经在Sourceforge上创建项目,并且源码 ...
- selenium测试(Java)--截图(十九)
package com.test.screenshot; import java.io.File; import java.io.IOException; import org.apache.comm ...
- TensorFlow基础笔记(0) tensorflow的基本数据类型操作
import numpy as np import tensorflow as tf #build a graph print("build a graph") #生产变量tens ...
- e671. 在缓冲图像中存取像素
// Get a pixel int rgb = bufferedImage.getRGB(x, y); // Get all the pixels int w = bufferedImage.get ...
- 用 #include <filename.h> 格式来引用标准库的头文件
用 #include <filename.h> 格式来引用标准库的头文件(编译器将从 标准库目录开始搜索). #include <iostream> /* run this p ...
- C++ 数据抽象
C++ 数据抽象数据抽象是指,只向外界提供关键信息,并隐藏其后台的实现细节,即只表现必要的信息而不呈现细节. 数据抽象是一种依赖于接口和实现分离的编程(设计)技术. 让我们举一个现实生活中的真实例子, ...
- poj2513(无向图判欧拉路)
链接:id=2513">点击打开链接 题意:一堆木棍左右两端涂有颜色,同样颜色的能够连接在一起,问全部木棍是否能都连上 代码: #include <map> #includ ...
- js openwindow
进入许多网站时,有弹出式小窗口,它们五花八门,使我们捉摸不透下面就来介绍用JS制作9种制作弹出小窗口: 1.最基本的弹出窗口代码 其实代码非常简单: < SCRI ...