当前位置:网站首页>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
边栏推荐
- Exercise 7-6 count capital consonants
- 数学常数表 by q779
- Too many files with unapproved license
- Exercise 10-8 recursive implementation of sequential output of integers
- 【7.3】146. LRU缓存机制
- 愉悦资本新双币基金近40亿元完成首次关账
- 7-6 mixed type data format input
- 【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?
- Leetcode(4)——寻找两个正序数组的中位数
- 论文分享:Generating Playful Palettes from Images
猜你喜欢

Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue

好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录

常见问题之PHP——ldap_add(): Add: Undefined attribute type in

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions

MySQL multi table query subquery

protobuf与grpc

Understand the application scenario and implementation mechanism of differential segment

concat和concat_ws()区别及group_concat()和repeat()函数的使用

Exercise 10-2 recursive factorial sum

7-11 calculation of residential water charges by sections
随机推荐
X86 assembly language - Notes from real mode to protected mode
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
Exercise 10-3 recursive implementation of exponential functions
China PETG market forecast and Strategic Research Report (2022 Edition)
npm install卡住与node-npy的各种奇怪报错
DDK for XP
剑指 Offer 28. 对称的二叉树
添加Zabbix计算类型项目Calculated items
Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
7-19 check denomination (solve binary linear equation)
Leetcode(4)——尋找兩個正序數組的中比特數
Doris学习笔记之数据表的创建
Thread. Sleep and timeunit SECONDS. The difference between sleep
关于回溯问题中的排列问题的思考(LeetCode46题与47题)
Solution to failure or slow downloading of electron when electron uses electron builder to package
Exercise 9-1 time conversion
Solr series of full-text search engines - basic principles of full-text search
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
7-22 tortoise and rabbit race (result oriented)
SSH访问控制,多次失败登录即封掉IP,防止暴力破解