题意:有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. Linux编译移植Qt4的环境_在OMAPL138平台

    Linux编译Qt4的环境_OMAPL138 手里有一块创龙OMAPL138的板子,我要在上面成功移植Qt环境和触摸屏幕,这是我第二次进行Linux的Qt环境移植,发现了很多问题,需要重新整理. 我编 ...

  2. Codeforces Round 97B 点分治

    B. Superset time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  3. Partitioning by Palindromes UVA - 11584 简单dp

    题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...

  4. python-13常用内建模块

    1-datetime #1-获取当前日期和时间 from datetime import datetime now = datetime.now() #当前时间 print(now) #2015-05 ...

  5. java实时监听日志写入kafka

    目的 实时监听某目录下的日志文件,如有新文件切换到新文件,并同步写入kafka,同时记录日志文件的行位置,以应对进程异常退出,能从上次的文件位置开始读取(考虑到效率,这里是每100条记一次,可调整) ...

  6. TouTiao开源项目 分析笔记6

    1.NewsChannelBean简单类笔记 1.1.Comparable接口的实现和使用 参考文章:Comparable接口的实现和使用. 因为NewsChannelBean实现了Comparabl ...

  7. TouTiao开源项目 分析笔记5

    1.深入理解RxJava 1.1.基本上现在的APP都会有请求网络,然后处理回调的业务吧. 如果请求的数据很多,业务越来越复杂,怎么处理呢? 这里我用到了RxJava来帮我处理业务. RxJava主要 ...

  8. vue-cli 引入axios

    写文章注册登录     首页 下载App × vue-cli 引入axios及跨域使用 星球小霸王 关注 2017.10.04 16:40* 字数 504 阅读 13038评论 2喜欢 18 使用 c ...

  9. spark发现新词

    package com.icklick.spark.wordSegment import org.apache.log4j.{ Level, Logger } import org.apache.sp ...

  10. 《Cracking the Coding Interview》——第18章:难题——题目7

    2014-04-29 03:05 题目:给定一个词典,其中某些词可能能够通过词典里其他的词拼接而成.找出这样的组合词里最长的一个. 解法:Leetcode上有Word Break这道题,和这题基本思路 ...