当前位置:网站首页>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
边栏推荐
- JS matrix zero
- SSH访问控制,多次失败登录即封掉IP,防止暴力破解
- Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
- Exercise 10-2 recursive factorial sum
- Learn to punch in today
- JS get DPI, PX to cm, cm to PX
- 适用于XP的DDK
- Protobuf and grpc
- Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
- 7-28 monkeys choose King (Joseph problem)
猜你喜欢
【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?
556. 下一个更大元素 III
分布式事务(Seata) 四大模式详解
US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
Sword finger offer 28 Symmetric binary tree
Exercise 8-7 string sorting
JS matrix zero
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
TS code automatically generates JS
随机推荐
GRPC的四种数据流以及案例
simpleParallax. JS (create poor visual effects for website pictures)
556. 下一个更大元素 III
JS input number and standard digit number are compared. The problem of adding 0 to 0
Accelerating strategy learning using parallel differentiable simulation
Statistical capital consonants
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
Leetcode(4)——尋找兩個正序數組的中比特數
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
7-4 BCD decryption (10 points)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
How Facebook moves instagram from AWS to its own server
SSH access control, blocking the IP when logging in repeatedly to prevent brute force cracking
泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东
FPGA blocking assignment and non blocking assignment
牛客网:过河卒
Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
x86汇编语言-从实模式到保护模式 笔记