poj 3172 Scales
来源:互联网 发布:9月经济数据 编辑:程序博客网 时间:2024/06/05 20:55
题意:已知天平秤的最大容量,给出若干砝码的重量。求解最多的重量。
思路:开始的时候看着像01背包的问题。但是此专题为搜索,看看数据很大,01估计会RE,所以进行搜索解决。寻找容量差值最小。dfs。
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;__int64 w[1005],sum[1005];//sum中存放前i个砝码的重量int n;__int64 c,minc;void dfs(int idex){ while(idex>0&&w[idex]>c) idex--; while(idex>0&&sum[idex]>c) { c=c-w[idex]; dfs(idex-1); c+=w[idex];//回溯 idex--;//无此句RE } if(c-sum[idex]<minc) minc=c-sum[idex];//最小的差值}int main(){ int k; while(scanf("%d%I64d",&n,&c)!=EOF) { memset(sum,0,sizeof(sum)); for(int i=1;i<=n;i++) { cin>>w[i]; sum[i]=sum[i-1]+w[i]; if(w[i]<c) k=i; } minc=c; dfs(k); cout<<c-minc<<endl; } return 0;}
- poj 3172 Scales
- poj 3172 Scales 搜索
- poj 3172 Scales
- POJ 3172 Scales
- POJ.3172 Scales (DFS)
- POJ 3172 Scales 笔记
- POJ scales
- POJ 3172 Scales(dfs搜索)
- POJ 3172 Scales (剪枝深搜)
- POJ 3172 Scales (01背包 DFS)
- POJ 3971 Scales(DP
- POJ 3971 Scales
- poj #3971:scales
- poj 3971 Scales (dp)
- Scales
- poj 3971 Scales (数位dp,好题)
- Scales HDU
- TOJ 3348 Scales
- PHP与UML类图: PHP and UML Class Diagrams
- HDU-4463-Outlets
- BT5无法启动图形界面问题
- 彩球分配问题:共有12个彩球,4个红的,4个白的,4个黄的,从中挑出8个球放入3个不同的口袋(口袋编号分别为a、b、c)编写程序打印输出所有可能的放法。
- AVL 树实现
- poj 3172 Scales
- css3手记
- Python 正则匹配学习
- gentoo双网卡绑定为bond
- eclipse导入jquery包后报错
- (++i)+(++i)+(++i)之类 顺序点和副作用
- poj 2842 窗口里的星星
- 图像的ASCII码显示v1—ASCII art--just for fun
- [10月31日的脚本] 在PowerPoint 2007中修改图片压缩分辨率设置