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

输入输出样例

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

解题思路

乍一看这道题是个以前讲过的贪心,就是按照力量和重量排序,但是这个还有个高度,并且问的是最大稳定,所以那种方法似乎不行。考虑状压,dp[S]表示选的状态为S时的最大承重,gg[S]表示所选为S时的最大高度,可以提前预处理出来。转移方程dp[S]=max(dp[S],min(dp[S^(1<

代码

#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
const int MAXN = 21;
typedef long long LL;

int H,n;
int dp[1<<MAXN],gg[1<<MAXN];
int w[MAXN],h[MAXN],a[MAXN];
int ans=-1;

int main(){
    memset(dp,-0x3f,sizeof(dp));dp[0]=0x3f3f3f3f;
    scanf("%d%d",&n,&H);
    for(register int i=1;i<=n;i++)
        scanf("%d%d%d",&h[i],&w[i],&a[i]);
    for(register int S=0;S<1<<n;S++)
        for(register int i=1;i<=n;i++)
            if(S&(1<<i-1)) gg[S]+=h[i];
    for(register int S=0;S<1<<n;S++){
        for(register int i=1;i<=n;i++)if(((S&(1<<i-1))))
            dp[S]=max(dp[S],min(a[i],dp[S^(1<<i-1)]-w[i]));
        if(gg[S]>=H && dp[S]>=0) ans=max(ans,dp[S]);
    }
    if(ans==-1) puts("Mark is too tall");
    else printf("%d",ans);
    return 0;
}

转载于:https://www.cnblogs.com/sdfzsyq/p/9676911.html

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下 4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值