Cow Exhibition(DP)

Cow Exhibition POJ - 2184【dp-01背包】 传送门 题意简述:奶牛想证明他们是聪明而风趣的。为此,贝西筹备了一个奶牛博览会,她已经对N头奶 牛进行了面试,确定了每头奶牛的智商和情商。 贝西有权选择让哪些奶牛参加展览。由于负的智商或情商会造成负面效果,所以贝西不 希望出展奶牛的智商之和小于零,或情商之和小于零。满足这两个条件下,她希望出展奶牛 的智商与情商之和越大越好,请帮助贝西求出这个最大值 分析 很容易想到这道题跟01背包有关系,区... 阅读详情

Description
“Fat and docile, big and dumb, they look so stupid, they aren’t much
fun…”
- Cows with Guns by Dana Lyons

The cows want to prove to the public that they are both smart and fun. In order to do this, Bessie has organized an exhibition that will be put on by the cows. She has given each of the N (1 <= N <= 100) cows a thorough interview and determined two values for each cow: the smartness Si (-1000 <= Si <= 1000) of the cow and the funness Fi (-1000 <= Fi <= 1000) of the cow.

Bessie must choose which cows she wants to bring to her exhibition. She believes that the total smartness TS of the group is the sum of the Si’s and, likewise, the total funness TF of the group is the sum of the Fi’s. Bessie wants to maximize the sum of TS and TF, but she also wants both of these values to be non-negative (since she must also show that the cows are well-rounded; a negative TS or TF would ruin this). Help Bessie maximize the sum of TS and TF without letting either of these values become negative.
Input
* Line 1: A single integer N, the number of cows

  • Lines 2..N+1: Two space-separated integers Si and Fi, respectively the smartness and funness for each cow.
    Output
  • Line 1: One integer: the optimal sum of TS and TF such that both TS and TF are non-negative. If no subset of the cows has non-negative TS and non- negative TF, print 0.

Sample Input
5
-5 7
8 -6
6 -3
2 1
-8 -5
Sample Output
8
Hint
OUTPUT DETAILS:

Bessie chooses cows 1, 3, and 4, giving values of TS = -5+6+2 = 3 and TF
= 7-3+1 = 5, so 3+5 = 8. Note that adding cow 2 would improve the value
of TS+TF to 10, but the new value of TF would be negative, so it is not
allowed.

一堆牛,有智商和情商,选出一些牛,在智商和和情商和都不为负数的前提下,求情商和智商和的最大。

昨天写了那么多题,头昏脑涨,今早看了一下发现就是背包,随便以智商或是情商为背包,求在这个智商下,情商的最大值,由于是要把容量完全装满,所以初始化除了dp[0] = 0;其他全为-inf。
然后wa了。
发现负数无法处理,可以看到数据范围是-1e5~1e5,可以加一个偏移量1e5即可。

还有一个优化就是每个情商是-1000到1000的,所以每次扩大搜索范围1000就行了,减少了很多不必要的更新。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
const int lea = 1e5;
int dp[200005];
struct Node
{
    int x,y;
}node[105];
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    int n,len = 200000;
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d%d",&node[i].x,&node[i].y);
    }
    for(int i = 0;i <= len;i++)dp[i] = -inf;
    dp[lea] = 0;
    for(int i = 1;i <= n;i++)
    {
        //if(node[i].x + node[i].y < 0)continue;
        if(node[i].x > 0)
            for(int j = lea + (i - 1)*1000 + node[i].x;j >= lea - (i - 1)*1000 + node[i].x;j--)
                dp[j] = max(dp[j],dp[j - node[i].x] + node[i].y);
        else
        {
            for(int j = lea - (i - 1)*1000 + node[i].x;j <= lea + (i - 1)*1000 + node[i].x;j++)
                dp[j] = max(dp[j],dp[j - node[i].x] + node[i].y);
        }
    }
    int ans = 0;
    for(int i = lea;i <= len;i++)
        if(dp[i] >= 0)
        ans = max(ans,i - lea + dp[i]);
    if(ans >= 0)
        printf("%d\n",ans);
    else
        printf("0\n");
    return 0;
}
S32K3基于EB配置GPT触发WDG的实战解析 本文详细解析了S32K3 MCU基于EB tresos工具配置GPT定时器触发看门狗(WDG)的实战方法。通过分析协同工作机制、MCAL配置步骤及代码实现,帮助开发者构建可靠的硬件监控系统,提升汽车电子系统的安全性与实时性。 阅读详情

相关推荐

告别PlatformIO!用Arduino IDE搞定ESP32上的micro-ROS 2.0.5(Humble版)

本文详细介绍了如何从PlatformIO迁移到Arduino IDE以支持ESP32上的micro-ROS 2.0.5(Humble版)。内容涵盖环境配置、项目转换、常见问题解决及高级优化技巧,帮助开发者顺利过渡并充分利用Arduino IDE的官方支持优势。

weixin_33709590的博客 376

POJ 2184 【01背包问题负权变体】

变化的01背包 题目描述: 题目:Cow Exhibition Description “Fat and docile, big and dumb, they look so stupid, they aren’t much fun…” Cows with Guns by Dana Lyons The cows want to prove to the public that they are...

tran_sient的博客 464

PADS Layout差分对布线实战:从规则设置到高速信号优化

本文详细讲解了在PADS Layout中进行差分对布线的完整实战流程。从在Layout中定义差分对网络,到进入Router配置线宽、间距等关键规则,再到布线实战技巧与高速信号完整性优化,系统阐述了如何确保差分信号(如USB、HDMI)的稳定传输,是高速PCB设计的核心技能。

weixin_29274969的博客 520

POJ2184 Cow Exhibition - 动态规划(dp) - 01背包问题

Cow Exhibition Time Limit: 1000MS     Memory Limit: 65536K Total Submissions: 17102     Accepted: 6998 Description “Fat and docile, big and dumb, they look so stupid, t...

太阳升起 265

雷达气象学(8)——反射率因子图实战(强对流预警篇)

本文聚焦雷达反射率因子图在强对流预警中的实战应用,深入解析了柱状回波、有界弱回波区(BWER)、三体散射(TBSS)等关键回波结构特征,这些是识别超级单体风暴和大冰雹的核心“身份证”。文章强调从静态识别转向动态追踪与多源数据综合研判的思维转变,并提供了系统的实战分析流程与常见误区避坑指南,旨在提升对强对流天气的短临预警能力。

weixin_29213827的博客 485

Unity UI适配实战:从Canvas Scaler到主流游戏适配方案解析

本文深入解析Unity UI适配的核心技术,重点介绍Canvas Scaler组件的关键参数如Reference Resolution和Screen Match Mode,并提供主流游戏适配方案实战分析。通过九宫格拉伸、动态调整等技巧,帮助开发者解决多设备适配难题,提升游戏UI在不同分辨率下的表现。

weixin_29001419的博客 970

POJ 2184 Cow Exhibition 背包问题

题目链接:POJ 2184 Cow Exhibition 题目 Description “Fat and docile, big and dumb, they look so stupid, they aren’t much fun…” Cows with Guns by Dana Lyons The cows want to prove to the public that they ar...

weixin_44273380的博客 243

IDCNBSAIS-财务报表功能范围取值管理费用、销售费用、研发费用排除指定科目的实现

研究了很多方法,没有办法实现,只在营业费用增加一个冲抵项解决,也咨询了外部顾问说要建立自建表。限于需要马上修正后面只能用了最最low的办法处理了一下。公司遇到的一个问题,目前报表有些项目是按照功能范围取值的,发现取多了。IDCNBSAIS-财务报表功能范围取值管理费用、销售费用、研发费用排除指定科目的实现。最后结果是正确的,但是总觉得有更好的办法,不知道有没有高人可以指点一下?建立一个调整项的目录,在每个节点做了调整。除了研发费用做了冲抵在以下每个节点都做了冲抵。为财务报表定义表格结构。

nopicture的博客 1491

【负数01背包】POJ-2184-Cowow-Exhibition

Description “Fat and docile, big and dumb, they look so stupid, they aren’t much fun…” Cows with Guns by Dana Lyons The cows want to prove to the public that they are both smart and fun. In order to do this, Bessie has organized an exhibition that will b

落花水面 256

基于Simulink的占空比调制DTC降低转矩脉动

修改传统SVPWM模块,输入占空比d和有效矢量索引,计算Ton​=d∗Tc​、Toff​=(1−d)∗Tc​,生成对称PWM波形(替代开关表直接输出)。:低速时(n<500rpm)减小dmax​=0.6(避免磁链畸变),高速时(n>2000rpm)增大dmax​=0.8(提升动态响应);kT​/kψ​:转矩/磁链误差增益(需整定,如kT​=0.02/(N⋅m),kψ​=0.1/Wb);(θ为电压矢量与磁链夹角)。② SVM-DTC(占空比计算模块启用,d0​=0.5,kT​=0.02,kψ​=0.1)。

amy_mhd的博客 87

VisionTransformer改进(11):结合CoordAtt注意力机制

​​CoordAtt模块​​:一个轻量级的坐标注意力机制​​ViT模型​​:基于标准Vision Transformer架构,但集成了CoordAtt模块模型最终通过CNNModel函数封装,虽然名称是CNN,但实际上是一个Transformer模型。引入了轻量级的CoordAtt注意力机制,增强了模型对空间位置信息的捕捉能力保持了ViT的主要优势,同时通过注意力机制提升了特征表示能力设计简洁高效,适合作为基础模型进行进一步研究和应用。

2401_82355416的博客 701

Cow Exhibition [POJ2184] [DP] [背包的负数处理]

题意: 有很多羊,每只羊有一个幽默度和智商,要选出一些羊,智商加幽默度总和最大,其中智商总和和幽默度总和都不能是负数。 样例输入: 5 -5 7 8 -6 6 -3 2 1 -8 -5 样例输出: 8 分析: 这很像一个01背包题,但是有两个价值,却没有重量 我们就把其中一个看成重量,另一个看成价值 答案就是max(i+dp[i]) 那如何保证数据大于0呢? 我...

weixin_30653097的博客 129

R语言实战应用精讲50篇(二)-多重线性回归系列之稳健回归

前言 线性回归的参数估计主要采用的是最小二乘法(又称最小平方法),该法是将使观测值与模型预测值之差的平方达到最小的值作为参数估计值。如果数据存在异常点或者异方差,最小二乘法估计会存在偏差,常用的处理策略就是改用稳健回归(Robust Regression)。 稳健回归就是采用更为稳健的参数估计方法来拟合模型,所谓稳健就是数据的波动对参数估计影响不大,比如不受异常值影响,或删除某一观测后对结果影响不大。稳健估计的方法有很多,主要有这么几类:最小绝对值回归(也称最小一乘法回归,lAV),最小中位数二乘法(L

wenyusuran的专栏 3160

[POJ 2184]Cow Exhibition[DP][01背包]

题目链接:[POJ 2184]Cow Exhibition[DP][01背包] 题意分析: 有n头牛,每头牛的智商为si,情商为fi,现在要举办一个展览,需要选择一些牛出来,满足这些牛的情商只和不小于0,智商之和不小于0,并且需要这两个之和的和最大化,问最大是多少?不存在则输出0。 解题思路: 将牛的智商作为背包容量,情商作为价值,那么最终答案就是:dp[i] + i。本题智商可为负,为了

闲停 543

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

[负数dp] poj 2184 Cow Exhibition

Cow Exhibition Time Limit:1000MS Memory Limit:65536K Total Submissions:16472 Accepted:6730 Description "Fat and docile, big and dumb, they look so stupid, they aren't much f...

qq_40738689的博客 266

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Luogu P2340 [USACO03FALL] Cow Exhibition G (线性DP 01背包转化)

奶牛想证明它们是聪明而风趣的。为此,贝西筹备了一个奶牛博览会,她已经对N头奶牛进行了面试,确定了每头奶牛的智商和情商。贝西有权选择让哪些奶牛参加展览。由于负的智商或情商会造成负面效果,所以贝西不希望出展奶牛的智商之和小于零,或情商之和小于零。满足这两个条件下,她希望出展奶牛的智商与情商之和越大越好,请帮助贝西求出这个最大值。

2302_79440616的博客 981

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【POJ】【DP】2184 Cow Exhibition

POJ 2184 Cow Exhibition 题目 ◇题目传送门◆ 题目大意 有NNN头奶牛,第iii头牛的属性值为si,fisi,fis_i,f_i,现要求选出一部分牛,使得其si,fisi,fis_i,f_i的总和尽可能的大,且满足:sisis_i之和为非负数,fifif_i之和为非负数。若不满足条件,则输出0。 思路 这道题每头奶牛有两个值。直接计算可能不太...

IDDFS 236

POJ 2184 Cow Exhibition [dp 背包]

题意: 给定两串数字,有正有服,求出最大和,且这个和的状态下满足任一边都不为负。 思路: dp。 说是背包,但是其实完全不懂背包的也可以做出来。 本质就是用dp数组来记录状态,然后依次增加状态和更新而已。。 值得注意的就是对负值平移成非负的。 linux环境下vim编辑器a掉的第二道题,很艰难,没少gdb。 强烈意识到要开始改装一下vim成ide了,利其器。 #i

Aszxqw 778

POJ2184——背包DP——Cow Exhibition

Description "Fat and docile, big and dumb, they look so stupid, they aren't muchfun..."- Cows with Guns by Dana LyonsThe cows want to prove to the public that they are both smart an...

dgjm4087的博客 134

pku 2184 Cow Exhibition(经典DP)

题意是给n组数,每组数中有S,T值,在其中选取若该组使其所有S+T和最大,要求左边S的和非负,且右边T的和非负。DP数组dp[i]表示当左边S的和为i时右边T的最大值,这样就很巧妙的装化成01背包问题了(这个是参考别人的)。那最后的解就是满足条件的Max{i+dp[i]}。#include using namespace std;const int base=100000;

low coder 1172

POJ 2184 Cow Exhibition (dp)

Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9687   Accepted: 3747 Description "Fat and docile, big and dumb, they look so stupid, they a

TaoSama's Microcosm 488

poj 2184 Cow Exhibition dp

《挑战》练习题,dp基础题。

ned_chu的博客 398

[DP] Cow Exhibition POJ - 2184 经典好题

poj.org/problem?id=2184 奶牛想证明他们是聪明而风趣的。为此,贝西筹备了一个奶牛博览会,她已经对N头奶 牛进行了面试,确定了每头奶牛的智商和情商。 贝西有权选择让哪些奶牛参加展览。由于负的智商或情商会造成负面效果,所以贝西不 希望出展奶牛的智商之和小于零,或情商之和小于零。满足这两个条件下,她希望出展奶牛 的智商与情商之和越大越好,请帮助贝西求出这个最大值 Input ...

蒟蒻的最后的倔强 285

2184 Cow Exhibition(背包dp)

Cow ExhibitionTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 14986 Accepted: 6068Description"Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with Guns by ...

baymax520的博客 218

Cow Exhibition POJ 2184(01背包dp)

原题 题目链接 题目分析 明显的01背包,但还是由细节需要处理,设置dp[i][j]=前i头牛中选的TF为j时最大的TS值,由于TF可能为负数因此要加一个基数使其在大于等于零,dp初始化为-1,dp[0][0]=0.更新的时候dp[i][j]=max(dp[i-1][j-f[i]]+s[i],dp[i-1][j]).观察这个dp的更新可以发现能状态压缩,当f[i]>=0时,j...

dashengchong6303的博客 197

POJ 2184 Cow Exhibition (dp 转换01背包)

题目:点击打开链接 题目大意: 有N个物品,每个物品有属性Si和Fi,-1000 思路: 这题想了很久都没思路,于是跟前辈请教了下,恍然大悟。把属性Si当做是物品的费用,Fi当做是价值,然后做01背包即可。 代码: #include #include #include #include #include #include #include #include

D_Double's Journey 1058
上一篇: Space Elevator(DP)
下一篇: Cable master(浮点数二分)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值