1673: [Usaco2005 Dec]Scales 天平

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 695  Solved: 253
[Submit][Status][Discuss]

Description

Farmer John has a balance for weighing the cows. He also has a set of N (1 <= N <= 1000) weights with known masses (all of which fit in 31 bits) for use on one side of the balance. He places a cow on one side of the balance and then adds weights to the other side until they balance. (FJ cannot put weights on the same side of the balance as the cow, because cows tend to kick weights in his face whenever they can.) The balance has a maximum mass rating and will break if FJ uses more than a certain total mass C (1 <= C < 2^30) on one side. The weights have the curious property that when lined up from smallest to biggest, each weight (from the third one on) has at least as much mass as the previous two combined. FJ wants to determine the maximum mass that he can use his weights to measure exactly. Since the total mass must be no larger than C, he might not be able to put all the weights onto the scale. Write a program that, given a list of weights and the maximum mass the balance can take, will determine the maximum legal mass that he can weigh exactly.

    约翰有一架用来称牛的体重的天平.与之配套的是N(1≤N≤1000)个已知质量的砝码(所有砝码质量的数值都在31位二进制内).每次称牛时,他都把某头奶牛安置在天平的某一边,然后往天平另一边加砝码,直到天平平衡,于是此时砝码的总质量就是牛的质量(约翰不能把砝码放到奶牛的那边,因为奶牛不喜欢称体重,每当约翰把砝码放到她的蹄子底下,她就会尝试把砝码踢到约翰脸上).天平能承受的物体的质量不是无限的,当天平某一边物体的质量大于C(1≤C<230)时,天平就会被损坏.    砝码按照它们质量的大小被排成一行.并且,这一行中从第3个砝码开始,每个砝码的质量至少等于前面两个砝码(也就是质量比它小的砝码中质量最大的两个)的质量的和.    约翰想知道,用他所拥有的这些砝码以及这架天平,能称出的质量最大是多少.由于天平的最大承重能力为C.他不能把所有砝码都放到天平上.
    现在约翰告诉你每个砝码的质量,以及天平能承受的最大质量.你的任务是选出一些砝码,
使它们的质量和在不压坏天平的前提下是所有组合中最大的.

Input

* Line 1: Two space-separated positive integers, N and C.

* Lines 2..N+1: Each line contains a single positive integer that is the mass of one weight. The masses are guaranteed to be in non-decreasing order.

    第1行:两个用空格隔开的正整数N和C.

第2到N+1行:每一行仅包含一个正整数,即某个砝码的质量.保证这些砝码的质量是一个不下降序列

Output

* Line 1: A single integer that is the largest mass that can be accurately and safely measured.

一个正整数,表示用所给的砝码能称出的不压坏天平的最大质量.

Sample Input

3 15
1
10
20

Sample Output

11

因为每个数都要大于前两个数之和,而int范围内的Fibonacci数不会超过45个,所以n<45

直接爆搜即可,理论复杂度2^45,但可以剪枝到0ms

#include<stdio.h>
#include<algorithm>
using namespace std;
#define LL long long
LL n, m, ans, a[1005], sum[1005];
void Sech(LL x, LL now)
{LL i;if(now+sum[x]<=ans)return;for(i=x;i<=n;i++){if(now+a[i]<=m){ans = max(ans, now+a[i]);if(i+1<=n)Sech(i+1, now+a[i]);}}
}
int main(void)
{LL i;scanf("%lld%lld", &n, &m);for(i=1;i<=n;i++)scanf("%lld", &a[i]);for(i=1;i<=n/2;i++)swap(a[i], a[n-i+1]);for(i=n;i>=1;i--)sum[i] = sum[i+1]+a[i];ans = 0;Sech(1, 0);printf("%lld\n", ans);return 0;
}

bzoj 1673: [Usaco2005 Dec]Scales 天平(DFS)相关推荐

  1. BZOJ 1673 [Usaco2005 Dec]Scales 天平:dfs 启发式搜索 A*搜索

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1673 题意: 有n个砝码(n <= 1000),重量为w[i]. 你要从中选择一些砝 ...

  2. bzoj 1671: [Usaco2005 Dec]Knights of Ni 骑士(BFS)

    1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 416  Solved: 26 ...

  3. bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(DP)

    1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 941  Solved ...

  4. bzoj 1671: [Usaco2005 Dec]Knights of Ni 骑士

    题目链接 题目背景: 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为了能安全地离开,贝茜不得不按照骑士们的要求,在森林寻找一种特殊的灌木 ...

  5. bzoj 1731 [Usaco2005 dec]Layout 排队布局——差分约束

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1731 对差分约束理解更深.还发现美妙博客:http://www.cppblog.com/me ...

  6. bzoj 1731: [Usaco2005 dec]Layout 排队布局【差分约束】

    差分约束裸题,用了比较蠢的方法,先dfs_spfa判负环,再bfs_spfa跑最短路 注意到"奶牛排在队伍中的顺序和它们的编号是相同的",所以\( d_i-d_{i-1}>= ...

  7. 1671: [Usaco2005 Dec]Knights of Ni 骑士

    1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 351  Solved: 22 ...

  8. 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 DP + 线段树 / SPFA

    1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 975  Solved ...

  9. bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐(暴力DFS)

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 774  Solved: 480 ...

最新文章

  1. 温泉关一役历史资料(电影:斯巴达300勇士)
  2. linux中信号的处理,linux中关于信号处理笔记(二)
  3. 数据结构实验之图论四:迷宫探索_用图机器学习探索 A 股个股相关性变化
  4. Deep Reinforcement Learning: Pong from Pixels
  5. 使用C#编程解决数独求解过程(从图片识别到数独求解)第二篇
  6. Windows堆栈区别[转]
  7. 第四章语法分析和语法分析程序
  8. 牛人(周志华)推荐的人工智能网站
  9. As we all know, Java 8 provides many new features
  10. oracle dataguard详解,Oracle 19c 新特性详解:DataGuard 中ADG的自动DML重定向
  11. java awt jar_【Java学习笔记】操作JAR文件
  12. 曾经用过的书生配置文档
  13. Supervisor管理hive服务(metastore,hiveserver2),防止意外杀死Hive服务,导致任务中断
  14. 电脑键盘功能基础知识大全分享
  15. ios html fixed,关于IOS的Safari浏览器fixed定位失效的那些坑
  16. Java http响应报文_java中HTTP响应报文是什么意思?详细图解
  17. 智能动环监控系统,实时排查机房安全隐患
  18. 易的核心理念之天道左旋、地道右旋
  19. 2020Q2中国家庭财富指数调研报告:疫情下中国家庭的财富变动趋势
  20. rust: error: no such subcommand: `+nightly-2021-12-14`

热门文章

  1. 线上python课程一般多少钱-python培训班一般多少钱?一篇文章告诉你
  2. QYResearch回顾:2017年中国汽车语音识别系统产量为1413万
  3. 语音识别下一步发展如何?哪些技术可以使用?哪些价值可以发掘?
  4. 工艺仿真软件_中科院科研项目:算法与软件工程集成电路制造中的工艺仿真
  5. vue中配置不同的代理同时访问不同的后台
  6. arcgis加载天地图_【arcgis地图实战】之天地图在线服务加载
  7. Media Player Classic - HC 源代码分析 4:核心类 (CMainFrame)(3)
  8. Oracle的字符串转换成二进制,将二进制字符串解析为文本/字符
  9. Helm 3 完整教程(十五):Helm 函数讲解(9)网络函数、文件路径函数、类型检查函数
  10. el表达式/jstl保留两位小数