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 ...
随机推荐
- 39.VUE学习--组件,子组件中data数据的使用,x-template模板的使用,改变for循环里的某条数据里的值
多处引用相同组件时,操作data不会相互影响 <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...
- PHP处理mysql事务
MYSQL的事务处理主要有两种方法.1.用begin,rollback,commit来实现begin 开始一个事务rollback 事务回滚commit 事务确认2.直接用set来改变mysql的自动 ...
- PyCharm 的安装与入门操作
PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元测试.版本控制. ...
- 3-1 练习 HTML 总结
1.段落 #段落 <div class="ui segment"> </div> #翻转 <div class="ui inverted s ...
- Error:Java home supplied via 'org.gradle.java.home' is invalid
Finally i found my solution. In the project root i found gradle.properties configure this java home ...
- python datetime offset-aware与offset-navie相互转换
python datetime offset-aware与offset-navie相互转换 2016年11月13日 16:20:43 阅读数:2393 有时,我们使用python 的datetime模 ...
- 《Cracking the Coding Interview》——第14章:Java——题目2
2014-04-26 18:44 题目:在java的try-catch-finally语句块里,如果catch里面有return语句的话,finally还会被执行吗? 解法:会. 代码: // 14. ...
- javascript将分,秒,毫秒转换为xx天xx小时xx秒(任何语言通用,最通俗易懂)
// 传入参数为总分钟数,如果为秒数,毫秒数,需要对 // 此处得到总秒数 注释部分的代码调整下. function toDateDMS(minutes){ // 将分钟转换为 天,时,分,秒 if( ...
- pdb在python程序中应用
1.什么是pdb? pdb是python提供的调试程序的一种工具. 2.为什么需要pdb模块? 当我们的程序越写越大的时候,我们用print xxx 这种方式打断点,调试,非常不方便,这个时候我们需要 ...
- css:hover状态改变另一个元素样式的使用
效果演示 css:hover状态改变另一个元素样式的使用 .box { width: 150px; height: 150px; background-color: #069; line-height ...