当前位置:网站首页>Luogu p5194 [usaco05dec]scales s solution
Luogu p5194 [usaco05dec]scales s solution
2022-07-03 14:27:00 【q779】
Luogu P5194 [USACO05DEC]Scales S Answer key
Topic link :P5194 [USACO05DEC]Scales S
The question :
John has a scale for weighing cows . What goes with it is N N N ( 1 ≤ N ≤ 1000 1 \leq N \leq 1000 1≤N≤1000 ) A weight of known mass ( The mass values of all weights are 32 Bit signed integer range ).
Every time you weigh a cow , He put a cow on one side of the scale , Then add weights to the other side of the balance , Until the balance is balanced , So the total mass of the weight at this time is the mass of the cow ( John can't put the weight on the side of the cow , Because cows don't like weighing , Whenever John puts the weight under her hoof , She would try to kick the weight in John's face ).
The mass of the object that the balance can bear is not infinite , When the mass of an object on one side of the balance is greater than C C C ( 1 ≤ C ≤ 2 30 1 \leq C \leq 2^{30} 1≤C≤230 ) when , The balance will be damaged . The weights are lined up according to their mass . also , In this line, from 3 Start with a weight , The mass of each weight is at least equal to the first two weights ( That is, the two weights with the largest mass among the weights with smaller mass ) The sum of the quality of .
John wants to know , With these weights and this balance he has , What is the maximum mass that can be weighed . Because the maximum bearing capacity of the balance is C C C , He can't put all the weights on the balance .
Now John tells you the mass of each weight , And the maximum mass that the balance can bear , Your task is to choose some weights , Make their mass and the largest of all combinations without crushing the balance .
Obviously, the search was violent + prune
We can reverse search , That is, choose the big one first
It is not difficult to find that this is more likely to produce a larger answer
And then mess around
Code :
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)(55)
int sum[N],mx,a[N],n,c;
void dfs(int now,int u)
{
if(u<1)
{
mx=max(mx,now);
return;
}
if(now+sum[u]<=mx) return;
if(now+a[u]<=c)dfs(now+a[u],u-1);
dfs(now,u-1);
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
cin >> n >> c;
for(int i=1; i<=n; i++)
{
cin >> a[i];
if(a[i]>c){
n=i-1;break;}
sum[i]=sum[i-1]+a[i];
}
dfs(0,n);
cout << mx << '\n';
return 0;
}
Reprint please explain the source
边栏推荐
- 洛谷P5536 【XR-3】核心城市 题解
- 7-10 calculate salary
- 基因家族特征分析 - 染色体定位分析
- Print. JS -- web page file printing
- 中国锂电池电解液行业市场专项调研报告(2022版)
- 7-20 print 99 formula table (format output)
- US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
- 7-11 calculation of residential water charges by sections
- SSH访问控制,多次失败登录即封掉IP,防止暴力破解
- Understanding of closures
猜你喜欢

Four data flows and cases of grpc

Protobuf and grpc

如何查询淘宝天猫的宝贝类目

Eight sorts

7-9 find a small ball with a balance

GRPC的四种数据流以及案例

JS input number and standard digit number are compared. The problem of adding 0 to 0

Doris学习笔记之数据表的创建

Exercise 10-2 recursive factorial sum

Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
随机推荐
Jiuyi cloud black free encryption free version source code
编程语言:类型系统的本质
动态获取权限
7-23 currency conversion (using array conversion)
基因家族特征分析 - 染色体定位分析
愉悦资本新双币基金近40亿元完成首次关账
Eight sorts
simpleParallax. JS (create poor visual effects for website pictures)
7-15 calculation of PI
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
7-6 mixed type data format input
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
Although not necessarily the best, it must be the hardest!
Add ZABBIX calculation type itemcalculated items
Interface for querying IP home
Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
Exercise 8-7 string sorting
ShowMeBug入驻腾讯会议,开启专业级技术面试时代
修改数据库中的记录为什么报这个错