题意:有n个小兵,每个小兵有a【i】血量,第一个人每次只能对一个小兵砍一滴血,第二个人每次对所有生存的小兵砍一滴血。

   最后看第一个人最多可以砍杀几个小兵。

/*
首先,如果所有小兵的血量都不同的话,我们可以杀死所有的小兵,如果所以我们应该尽量使小兵血量不同,
也就是在不能将某个小兵一击致命的情况下,对某个某个血量相同的小兵砍一刀,使其血量不同。
预处理出c[i]表示i血量这个位置上的小兵是由c[i]血量的小兵砍过来的。
dp[i][j]表示进行了i轮之后,留有的砍兵机会为j次的最大值。
dp[i][j]=max(dp[i-1][j-1],dp[i-1][j+c[i]-i])
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 1010
using namespace std;
int c[N],d[N],dp[N][N],s[N],n,m,top,cas;
int main(){
int T;scanf("%d",&T);
while(T--){
m=,top=;
memset(d,,sizeof(d));
memset(c,,sizeof(c));
memset(dp,,sizeof(dp));
scanf("%d",&n);
for(int i=;i<=n;i++){
int x;scanf("%d",&x);
d[x]++;m=max(m,x);
}
for(int i=;i<=m;i++){
if(d[i]==) c[i]=i;
else if(d[i]==) s[++top]=i;
else {
c[i]=i;
while(top&&d[i]>){
int x=s[top];
if(i-x<=top){
top--;
c[x]=i;
d[i]--;
}
else break;
}
}
}
for(int i=;i<=m;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<=m;i++)
ans=max(ans,dp[m][i]);
printf("Case #%d: %d\n",++cas,ans);
}
return ;
}

A simple greedy problem(hdu 4976)的更多相关文章

  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 1757 A Simple Math Problem (矩阵乘法)

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

  3. HDU - 5974 A Simple Math Problem (数论 GCD)

    题目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least ...

  4. A Simple Math Problem(HDU 1757 构造矩阵)

    If x < 10 f(x) = x.If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-1 ...

  5. HDU-1757--A Simple Math Problem(矩阵乘法)

    Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) = x.If x > ...

  6. 2013多校联合3 G The Unsolvable Problem(hdu 4627)

    2013-07-30 20:35 388人阅读 评论(0) 收藏 举报 http://acm.hdu.edu.cn/showproblem.php?pid=4627 The Unsolvable Pr ...

  7. ZOJ 3686 A Simple Tree Problem(线段树)

    Description Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the ...

  8. bzoj3489: A simple rmq problem (主席树)

    //========================== 蒟蒻Macaulish:http://www.cnblogs.com/Macaulish/  转载要声明! //=============== ...

  9. BestCoder Round #70 Jam's math problem(hdu 5615)

    Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...

随机推荐

  1. wps取消英文首字母大写功能

    wps中关于首字母大写的功能还是很有用处的,但是有时候对于我们来说却是一种累赘,怎么取消这个功能呢? 新建一个文档之后,点击wps文字,选择工具,选项按钮 然后点击编辑,取消勾选键入时自动进行首字母大 ...

  2. ZOJ3329 概率DP

    One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very ...

  3. 将Mnist手写数字库转化为图片形式 和标签形式

    Mnist 数据文件有两种,一种是图片文件,一种是标签文件,那么如何把他们解析出来呢? (1)解析图片文件 可以看出在train-images.idx3-ubyte中,第一个数为32位的整数(魔数,图 ...

  4. 十三、MySQL之IDE工具介绍及数据备份

    一.IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 二.MySQL数据备份 # ...

  5. 原码、反码、补码、BCD码、格雷码

    二进制的最高位表示这个二进制的正负符号(0为正,1为负),其余各位数表示其数值本身称为原码. 正数的反码等于原码,负数的反码是在原码的基础上,符号位不变,其余各位取反. 正数的补码等于原码,负数的补码 ...

  6. MethodTrace 生成的trace文件为空

    今天我准备生成一个trace文件,看看程序卡在哪里. 一般: Debug.startMethodTracing("yuge"); Debug.stopMethodTracing() ...

  7. hadoop中namenode发生故障的处理方法

    Namenode 故障后,可以采用如下两种方法恢复数据: 方法一:将 SecondaryNameNode 中数据拷贝到 namenode 存储数据的目录: 方法 二: 使用 -importCheckp ...

  8. ios交叉编译dylib

    ios交叉编译dylib 因多个静态库,libes,libffmpeg,libmt. libpcap 使用不方便 在封装一层接口,生成动态库(c代码),由IOS app上层调用. IOS_BASE_S ...

  9. Installing Nginx With PHP5 (And PHP-FPM) And MySQL Support (LEMP) On Ubuntu 12.04 LTS [repost]

    from : http://www.howtoforge.com/installing-nginx-with-php5-and-php-fpm-and-mysql-support-lemp-on-ub ...

  10. 让NVelocity做更多的事,VS Extension+NVelocity系列

    我不知道园子里到底有多少人喜欢使用NVelocity这个模板引擎,其实说实话,如果现在让我选,我对Razor的喜好要比NVelocity或者T4等等的模板引擎更多一些,当然了,个人看法而已.只是我在公 ...