天平难题
来源:互联网 发布:linux telnet 类似 编辑:程序博客网 时间:2024/04/28 05:12
#include<cstdio>#include<cstring>#include<vector>#include<algorithm>using namespace std;const int maxn = 7;struct Tree{double l, r;Tree() : l(0), r(0) {}};bool vis[1<<maxn];double r, w[maxn], sum[1<<maxn];vector<Tree> tree[1<<maxn];void dfs(int root){if(vis[root]) return;vis[root] = true;bool have_kid = false;for(int left = (root-1)&root; left; left = (left-1)&root){have_kid = true;int right = root^left;double d1 = sum[right]/sum[root], d2 = sum[left]/sum[root];dfs(left); dfs(right);for(int i = 0; i < tree[left].size(); i++){for(int j = 0; j < tree[right].size(); j++){Tree t;t.l = max(d1+tree[left].l, tree[right].l-d2);t.r = max(d2+tree[right].r, tree[left].r-d1);if(t.l+t.r < r) tree[root].push_back(t);}}}if(!have_kid) tree[root].push_back(Tree());}int main(){int n;scanf("%lf%d", &r, &n);for(int i = 0; i < n; i++) scanf("%lf", &w[i]);for(int i = 0; i < (1<<n); i++){tree[i].clear();sum[i] = 0;for(int j = 0; j < n; j++)if((1<<j) & i) sum[i] += w[j];}int root = (1<<n)-1;memset(vis, 0, sizeof(vis));dfs(root);double ans = -1;for(int i = 0; i < tree[root].size(); i++)ans = max(ans, tree[root][i].l+tree[root][i].r);printf("%.10lf\n", ans);return 0;}
0 0
- 天平难题
- LA3403 天平难题
- Uva1354-天平难题
- 天平难题 UVa 1354
- 例题7-7 天平难题 UVa1354
- LA3403天平难题(4个DFS)
- 例题7-7 天平难题 UVa1354 **
- 天平难题(Mobile Computing,UVa 1354)
- 天平难题(Mobile ComputingUVa 1354)
- uva1354 天平难题 位枚举子集
- 天平难题(Mobile Computing, ACM/ICPC Tokyo
- 搜索 【uva1354】 Mobile Computing (练习题7-7 天平难题)
- 天平
- 例题7-7 天平难题(Mobile Computing, ACM/ICPC Tokyo 2005, UVa1354)
- 难题
- 难题
- 难题
- 难题
- 基本元器件之美标螺丝UNC/UNF螺纹
- iOS回顾笔记(05) -- 手把手教你封装一个广告轮播图框架
- Spring学习笔记
- 九度OJ-题目1011 最大连续子序列
- 创建Git远程仓库
- 天平难题
- VB.NET邮件群发纯htlm二维码
- 浮点和布尔数据类型
- 【图像特征提取15】Fast原理及源码解析
- 团体程序设计天梯赛-练习集 L2-014. 列车调度 解题报告
- 3对象的共享
- Niro plays Galaxy Note 7
- mysql数据通过fluent同步到阿里云datahub填坑过程
- Android Custom View --- 水波纹效果