洛谷P3112 [USACO14DEC]后卫马克Guard Mark
题目描述
Farmer John and his herd are playing frisbee. Bessie throws the
frisbee down the field, but it's going straight to Mark the field hand
on the other team! Mark has height H (1 <= H <= 1,000,000,000), but
there are N cows on Bessie's team gathered around Mark (2 <= N <= 20).
They can only catch the frisbee if they can stack up to be at least as
high as Mark. Each of the N cows has a height, weight, and strength.
A cow's strength indicates the maximum amount of total weight of the
cows that can be stacked above her.
Given these constraints, Bessie wants to know if it is possible for
her team to build a tall enough stack to catch the frisbee, and if so,
what is the maximum safety factor of such a stack. The safety factor
of a stack is the amount of weight that can be added to the top of the
stack without exceeding any cow's strength.
FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark
被N(2 <= N <= 20)头牛包围。牛们可以叠成一个牛塔,如果叠好后的高度大于或者等于Mark的高度,那牛们将抢到飞盘。
每头牛都一个身高,体重和耐力值三个指标。耐力指的是一头牛最大能承受的叠在他上方的牛的重量和。请计算牛们是否能够抢到飞盘。若是可以,请计算牛塔的最大稳定强度,稳定强度是指,在每头牛的耐力都可以承受的前提下,还能够在牛塔最上方添加的最大重量。
输入输出格式
输入格式:
INPUT: (file guard.in)
The first line of input contains N and H.
The next N lines of input each describe a cow, giving its height,
weight, and strength. All are positive integers at most 1 billion.
输出格式:
OUTPUT: (file guard.out)
If Bessie's team can build a stack tall enough to catch the frisbee, please output the maximum achievable safety factor for such a stack.
Otherwise output "Mark is too tall" (without the quotes).
输入输出样例
4 10
9 4 1
3 3 5
5 5 10
4 4 5
2
动规 状压DP
看到数据范围就是状压DP了吧233
有那么一阵子我有DFS可以剪枝强行卡过去的错觉,然而果然是错觉。
f[i]记录的是当前状态(状压当前有哪些牛)的最大安全因子是多大
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
int f[<<];
int g[<<];
struct node{
int h,w,s;
}a[mxn];
int n,H;
int ans=-;
int main(){
int i,j;
n=read();H=read();int smm=;
for(i=;i<n;i++){
a[i].h=read();a[i].w=read();a[i].s=read();
smm+=a[i].h;
}
if(smm<H){printf("Mark is too tall\n");return ;}
memset(f,-,sizeof f);
f[]=INF;
int ed=(<<n)-;
for(i=;i<=ed;i++){
for(j=;j<n;j++){
if((i>>j)&)continue;
int v=i^(<<j);
if(f[i]<a[j].w)continue;
int t=min(f[i]-a[j].w,a[j].s);
f[v]=max(f[v],t);
g[v]=g[i]+a[j].h;//累计高度
if(v && g[v]>=H)ans=max(ans,f[v]);
}
}
if(ans==-)printf("Mark is too tall\n");
else printf("%d\n",ans);
return ;
}
洛谷P3112 [USACO14DEC]后卫马克Guard Mark的更多相关文章
- 洛谷 P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- 洛谷 3112 [USACO14DEC]后卫马克Guard Mark——状压dp
题目:https://www.luogu.org/problemnew/show/P3112 状压dp.发现只需要记录当前状态的牛中剩余承重最小的值. #include<iostream> ...
- LUOGU P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- [Luogu3112] [USACO14DEC]后卫马克Guard Mark
题意翻译 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果叠 ...
- [USACO14DEC]后卫马克Guard Mark
题目描述 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark 被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果 ...
- 洛谷 P3112 后卫马克Guard Mark
->题目链接 题解: 贪心+模拟 #include<algorithm> #include<iostream> #include<cstring> #incl ...
- 洛谷 P3112 后卫马克 —— 状压DP
题目:https://www.luogu.org/problemnew/show/P3112 状压DP...转移不错. 代码如下: #include<iostream> #include& ...
- 洛谷P3110 [USACO14DEC]驮运Piggy Back
P3110 [USACO14DEC]驮运Piggy Back 题目描述 贝西和她的妹妹艾尔斯白天在不同的地方吃草,而在晚上他们都想回到谷仓休息.聪明的牛仔,他们想出了一个计划,以尽量减少他们在步行时花 ...
- 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...
随机推荐
- php扩展开发-常量
//常量在内核中的结构 typedef struct _zend_constant { zval value; int flags; char *name; uint name_len; int mo ...
- 从coding.net 克隆(git clone)项目代码到本地报无权限(403)错误 解决方案
直接从coding.net (git clone)项目代码到本地时,会提示没有权限的错误,如下图: 解决方案:添加远程地址的时候带上用户名及密码即可解决,格式如下: git clone http:// ...
- python入门基本知识
1. 什么是语言 语言是一个事物与另外一个事物沟通的介质. python则是人(程序员)与计算机沟通的介质. 2. 什么是编程 编程就是程序员将自己想要让计算机做的事情用编程语言翻译出来写到一系列的文 ...
- sed命令例子详解
sed -e '/Patricia/h' -e '/Margot/x' datafile 包含Margot的行将被包含Patricia的行替换: sed -e /WE/{h;d;}' -e '/CT/ ...
- 1 Mongodb安装
1.NoSQL简介 NoSQL,全名Not Only SQL,指的是非关系型的数据库 随着访问量的上升,网站的数据库性能出现了问题,于是NoSQL被设计出来了 优点.缺点 优点 高扩展性 分布式计算 ...
- CodeForces 785C Anton and Fairy Tale 二分
题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...
- mybatis异常:There is no getter for property named 'xxx' in 'xxx'
在使用mybatis查询的时候出现了下面的异常: org.apache.ibatis.reflection.ReflectionException: There is no getter for pr ...
- RegisterWindowMessage
RegisterWindowMessage function Defines a new window message that is guaranteed to be unique throug ...
- laravel5.5入口文件分析
入口文件 public/index.php 1.加载composer的自动加载器 require __DIR__.'/../vendor/autoload.php'; 自动加载,不用再各种requir ...
- shell编程——
一.分支语句 语法:(多路分支) case word in patterm1) list A ;; pattern2) list B ;; patternN) list N ;; esac例子:cas ...