标签:
Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 666 | Accepted: 224 | Special Judge |
Description
Input
Output
Sample Input
5 1.3 3 1 2 1 1.4 3 1 2 1 2.0 3 1 2 1 1.59 4 2 1 1 3 1.7143 4 1 2 3 5
Sample Output
-1 1.3333333333333335 1.6666666666666667 1.5833333333333335 1.7142857142857142
Source
// // main.cpp // poj2743 // // Created by Candy on 9/28/16. // Copyright © 2016 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; const int N=6; double r,sum[1<<N]; int n,w[N],T,vis[1<<N]; struct node{ double l,r; int ls,rs; node():l(0),r(0){} }; vector<node> tree[1<<N]; void dfs(int subset){//printf("dfs %d\n",subset); if(vis[subset]) return; vis[subset]=1; int child=0; for(int left=(subset-1)⊂left;left=(left-1)&subset){ child=1; int right=left^subset; dfs(left);dfs(right); double dl=sum[right]/sum[subset],dr=sum[left]/sum[subset]; for(int i=0;i<tree[left].size();i++) for(int j=0;j<tree[right].size();j++){ node t; t.l=max(tree[left][i].l+dl,tree[right][j].l-dr); t.r=max(tree[left][i].r-dl,tree[right][j].r+dr); if(t.l+t.r<r) tree[subset].push_back(t); } } if(!child) tree[subset].push_back(node());//leaf } int main(int argc, const char * argv[]) { scanf("%d",&T); while(T--){ scanf("%lf%d",&r,&n); for(int i=0;i<n;i++) scanf("%d",&w[i]); for(int i=0;i<(1<<n);i++){ sum[i]=vis[i]=0; tree[i].clear(); for(int j=0;j<n;j++) if(i&(1<<j)) sum[i]+=w[j]; } //for(int i=0;i<(1<<n);i++) printf("sum %d\n",sum[i]); int root=(1<<n)-1; 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("%.10f\n",ans); } return 0; }
POJ2743Mobile Computing[DFS 状态压缩]
标签:
原文地址:http://www.cnblogs.com/candy99/p/5918400.html