A simple greedy problem(hdu 4976)
题意:有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)的更多相关文章
- 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 1757 A Simple Math Problem (矩阵乘法)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 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 ...
- 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 ...
- 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 > ...
- 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 ...
- 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 ...
- bzoj3489: A simple rmq problem (主席树)
//========================== 蒟蒻Macaulish:http://www.cnblogs.com/Macaulish/ 转载要声明! //=============== ...
- 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 ...
随机推荐
- 特殊sql查询方法实例
一.if条件查询:SELECT sum(if(is_buy > 0 ,1,0)) AS friend_count_all_cj, sum(if(is_buy = 0 ,1,0)) AS frie ...
- Jongmah CodeForces - 1110D
传送门 题意:你有n个数字,范围[1, m],你可以选择其中的三个数字构成一个三元组,但是这三个数字必须是连续的或者相同的,每个数字只能用一次,问这n个数字最多构成多少个三元组? 题解:三个一模一样的 ...
- Codeforces Round 97B 点分治
B. Superset time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- POJ:1222-EXTENDED LIGHTS OUT(矩阵反转)
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12956 Accepted: 8186 ...
- 使wlr写cnblog的博客-2 设置cnblog帐号
ref:http://www.cnblogs.com/liuxianan/archive/2013/04/13/3018732.html 使用: 打开Windows Live Writer,第一次 ...
- CSS继承特殊
继承 CSS的某些样式具有继承性.继承是一种规则,它允许样式不仅作用于某个特定html标签元素,而且应用于其后代 如:在p中的所有字体都为红色 p{color:red;} <p ...
- 自定义控件的getChildCount
我真的是一步一步走过来,看过来的代码.不是能力问题,而是他们用的,我没用过,我用的他们不用.然后一句一句的问为什么,然后一句一句的去想为什么. 只有这样,才能慢慢的熟悉,东一榔头西一棒子,不是分模块再 ...
- 跨站请求伪造(csrf)中间件整理
一. CSRF中间件 字面意思跨站请求伪造; 即模仿个请求朝服务器发送,django中对跨站伪造的请求有相应的校验 from django.views.decorators.csrf import c ...
- latex排版系统
proTeXt - MiKTeX-based distribution for Windows proTeXt aims to be an easy-to-install TeX distributi ...
- Jenkins拾遗--第三篇(用户权限管理)
采访过很多实用Jenkins的同学,发现Jenkins的安全是一个很薄弱的地方.很多公司用作生产部署的Jenkins安全管理都不是很规范,就更别提测试用的Jenkins了. 其实Jenkins是一个很 ...