当前位置:网站首页>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
边栏推荐
- 7-11 calculation of residential water charges by sections
- Exercise 6-2 using functions to sum special A-string sequences
- TS code automatically generates JS
- 愉悦资本新双币基金近40亿元完成首次关账
- MongoDB索引
- Sword finger offer 28 Symmetric binary tree
- Find the sum of the elements of each row of the matrix
- 剑指 Offer 28. 对称的二叉树
- Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
- 7-22 tortoise and rabbit race (result oriented)
猜你喜欢
Exercise 10-3 recursive implementation of exponential functions
retrofit
Four data flows and cases of grpc
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Doris学习笔记之数据表的创建
Exercise 9-3 plane vector addition
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
JS matrix zero
编程语言:类型系统的本质
随机推荐
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
ConstraintLayout 的使用
Zabbix添加Calculated items后保存页面成空白
洛谷P5194 [USACO05DEC]Scales S 题解
Mongodb index
分布式事务(Seata) 四大模式详解
Exercise 10-2 recursive factorial sum
Exercise 8-7 string sorting
Add ZABBIX calculation type itemcalculated items
Stop asking yourself if you are suitable for software testing
Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million
fpga阻塞赋值和非阻塞赋值
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
Why is this error reported when modifying records in the database
7-17 crawling worms (break exercise)
7-18 finding the single root of polynomial by dichotomy
Learn to punch in today
PCB中常用快捷键