当前位置:网站首页>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
边栏推荐
- C language,%d% Difference between 2D%2d%02d
- fpga阻塞赋值和非阻塞赋值
- Print. JS -- web page file printing
- 6-9 statistics of single digits (15 points)
- 中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
- Etcd cluster permission management and account password usage
- 556. The next larger element III
- [clean up the extraordinary image of Disk C]
- ZABBIX saves the page blank after adding calculated items
- 必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
猜你喜欢

编程语言:类型系统的本质

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

Exercise 10-8 recursive implementation of sequential output of integers

Exercise 8-7 string sorting

天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库

必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿

论文分享:Generating Playful Palettes from Images

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

Exercise 10-1 calculate the sum of 1 to n using recursive functions

Exercise 10-2 recursive factorial sum
随机推荐
Common commands for getting started with mongodb database
Although not necessarily the best, it must be the hardest!
7-18 finding the single root of polynomial by dichotomy
JS matrix zero
JS get DPI, PX to cm, cm to PX
7-20 print 99 formula table (format output)
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
LNMP环境mail函数不能发送邮件解决
虽然不一定最优秀,但一定是最努力的!
Duet date picker (time plug-in that can manually enter the date)
J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
中感微冲刺科创板:年营收2.4亿净亏1782万 拟募资6亿
2021年区域赛ICPC沈阳站J-Luggage Lock(代码简洁)
ZABBIX saves the page blank after adding calculated items
7-23 currency conversion (using array conversion)
protobuf与grpc
Four data flows and cases of grpc
Mongodb index
论文分享:Generating Playful Palettes from Images
FPGA blocking assignment and non blocking assignment