bzoj 1673: [Usaco2005 Dec]Scales 天平(DFS)
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.
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.
第2到N+1行:每一行仅包含一个正整数,即某个砝码的质量.保证这些砝码的质量是一个不下降序列
Output
* Line 1: A single integer that is the largest mass that can be accurately and safely measured.
一个正整数,表示用所给的砝码能称出的不压坏天平的最大质量.
Sample Input
Sample Output
因为每个数都要大于前两个数之和,而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)相关推荐
- BZOJ 1673 [Usaco2005 Dec]Scales 天平:dfs 启发式搜索 A*搜索
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1673 题意: 有n个砝码(n <= 1000),重量为w[i]. 你要从中选择一些砝 ...
- 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 ...
- bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(DP)
1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 941 Solved ...
- bzoj 1671: [Usaco2005 Dec]Knights of Ni 骑士
题目链接 题目背景: 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为了能安全地离开,贝茜不得不按照骑士们的要求,在森林寻找一种特殊的灌木 ...
- bzoj 1731 [Usaco2005 dec]Layout 排队布局——差分约束
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1731 对差分约束理解更深.还发现美妙博客:http://www.cppblog.com/me ...
- bzoj 1731: [Usaco2005 dec]Layout 排队布局【差分约束】
差分约束裸题,用了比较蠢的方法,先dfs_spfa判负环,再bfs_spfa跑最短路 注意到"奶牛排在队伍中的顺序和它们的编号是相同的",所以\( d_i-d_{i-1}>= ...
- 1671: [Usaco2005 Dec]Knights of Ni 骑士
1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 351 Solved: 22 ...
- 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 DP + 线段树 / SPFA
1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 975 Solved ...
- bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐(暴力DFS)
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 774 Solved: 480 ...
最新文章
- 温泉关一役历史资料(电影:斯巴达300勇士)
- linux中信号的处理,linux中关于信号处理笔记(二)
- 数据结构实验之图论四:迷宫探索_用图机器学习探索 A 股个股相关性变化
- Deep Reinforcement Learning: Pong from Pixels
- 使用C#编程解决数独求解过程(从图片识别到数独求解)第二篇
- Windows堆栈区别[转]
- 第四章语法分析和语法分析程序
- 牛人(周志华)推荐的人工智能网站
- As we all know, Java 8 provides many new features
- oracle dataguard详解,Oracle 19c 新特性详解:DataGuard 中ADG的自动DML重定向
- java awt jar_【Java学习笔记】操作JAR文件
- 曾经用过的书生配置文档
- Supervisor管理hive服务(metastore,hiveserver2),防止意外杀死Hive服务,导致任务中断
- 电脑键盘功能基础知识大全分享
- ios html fixed,关于IOS的Safari浏览器fixed定位失效的那些坑
- Java http响应报文_java中HTTP响应报文是什么意思?详细图解
- 智能动环监控系统,实时排查机房安全隐患
- 易的核心理念之天道左旋、地道右旋
- 2020Q2中国家庭财富指数调研报告:疫情下中国家庭的财富变动趋势
- rust: error: no such subcommand: `+nightly-2021-12-14`
热门文章
- 线上python课程一般多少钱-python培训班一般多少钱?一篇文章告诉你
- QYResearch回顾:2017年中国汽车语音识别系统产量为1413万
- 语音识别下一步发展如何?哪些技术可以使用?哪些价值可以发掘?
- 工艺仿真软件_中科院科研项目:算法与软件工程集成电路制造中的工艺仿真
- vue中配置不同的代理同时访问不同的后台
- arcgis加载天地图_【arcgis地图实战】之天地图在线服务加载
- Media Player Classic - HC 源代码分析 4:核心类 (CMainFrame)(3)
- Oracle的字符串转换成二进制,将二进制字符串解析为文本/字符
- Helm 3 完整教程(十五):Helm 函数讲解(9)网络函数、文件路径函数、类型检查函数
- el表达式/jstl保留两位小数