题目描述

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).

输入输出样例

输入样例#1:

4 10
9 4 1
3 3 5
5 5 10
4 4 5
输出样例#1:

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的更多相关文章

  1. 洛谷 P3112 [USACO14DEC]后卫马克Guard Mark

    题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...

  2. 洛谷 3112 [USACO14DEC]后卫马克Guard Mark——状压dp

    题目:https://www.luogu.org/problemnew/show/P3112 状压dp.发现只需要记录当前状态的牛中剩余承重最小的值. #include<iostream> ...

  3. LUOGU P3112 [USACO14DEC]后卫马克Guard Mark

    题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...

  4. [Luogu3112] [USACO14DEC]后卫马克Guard Mark

    题意翻译 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果叠 ...

  5. [USACO14DEC]后卫马克Guard Mark

    题目描述 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark 被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果 ...

  6. 洛谷 P3112 后卫马克Guard Mark

    ->题目链接 题解: 贪心+模拟 #include<algorithm> #include<iostream> #include<cstring> #incl ...

  7. 洛谷 P3112 后卫马克 —— 状压DP

    题目:https://www.luogu.org/problemnew/show/P3112 状压DP...转移不错. 代码如下: #include<iostream> #include& ...

  8. 洛谷P3110 [USACO14DEC]驮运Piggy Back

    P3110 [USACO14DEC]驮运Piggy Back 题目描述 贝西和她的妹妹艾尔斯白天在不同的地方吃草,而在晚上他们都想回到谷仓休息.聪明的牛仔,他们想出了一个计划,以尽量减少他们在步行时花 ...

  9. 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

    P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...

随机推荐

  1. python__系统 : socket_UDP相关

    socket.socket() 可以创建一个套接字: from socket import * from threading import Thread udp_socket = None dest_ ...

  2. python语法练习题之九九乘法表

    九九乘法表 for...in方法实现 # 方法一 for i in range(1, 10): for j in range(1, i+1): print('{}*{}={:<4}'.forma ...

  3. Apache安装之后,在浏览器输入ip无法访问

    博主本来在linux下面配置安装了apache,然后用浏览器输入ip却无法访问 就一直在想是不是dns无法解析的问题,最后才发现原来是防火墙的原因, 在linux下面 service iptables ...

  4. BZOJ 3027: [Ceoi2004]Sweet

    容斥 #include<cstdio> using namespace std; int a,b,n,m[15]; long long ans=0,mod=2004; long long ...

  5. android gradle 给所有的buildFlavor 的versionName 增加一个后缀

    build里面有很多的productFlavors,我想要给所有的productFlavors 的versionName增加一个后缀比如:_20180323 怎么做?注意是所有的productFlav ...

  6. __bridge 使用注意

    前奏 在平常开发中,我们可能遇到 CoreFoundation(CF) 框架的对象和 OC 对象之间的类型转换,这时候我们需要 __bridge 来帮忙 注意 : 如果是使用 CF __bridge ...

  7. MD5--3D模型

    在学习Away3D的过程中,接触到MD5模型和MD5动画这样两个词.之前对MD5的认识就是一种加密技术,怎么它又和动画扯上关系了呢. 一阵谷歌之后,终于在这个地方发现了关于3D方面的MD5介绍了:ht ...

  8. 《Cracking the Coding Interview》——第17章:普通题——题目11

    2014-04-29 00:00 题目:给定一个rand5()函数,能够返回0~4间的随机整数.要求实现rand7(),返回0~6之间的随机整数.该函数产生随机数必须概率相等. 解法:自己想了半天没想 ...

  9. shell脚本从文件夹中递归提取文件

    需求 前两天碰到需要在十层左右的文件夹中提取文件的需求,于是写了此脚本. 如下面这样的文件结构: dir1 ├── a │ ├── b │ │ └── file1 │ └── file2 ├── c ...

  10. Spring+SpringMVC+MyBatis+Redis框架学习笔记

    在Java互联网中,以Spring+Spring MVC+MyBatis (SSM) 作为主流框架. SSM+Redis的结构图 在这种框架系统中: Spring IoC 承担了一个资源管理.整合.即 ...