3 Lessons to a This problem, and finally timed out, is also pretty spelling.
I didn't do it. The main aspect is not to enumerate a subset of binary numbers
Here's the code:
for (int S0 = S; S0; S0 = (s0-1) & S) { }
Here S0 is a subset of s!
The idea of the topic is to enumerate all the circumstances, attention to memory "said the problem learned a lot"
#include <cstdio> #include <cstring> #include <vector> #include <algorithm>using namespace std ;//Enumerate the shape of the binary tree const int MAXN = 8;const int maxd = (1 << 8); int n;double ww;int w[maxn];int sum[maxd];int Vis[maxd];d Oub Le ret;struct node{double l,r; Node (double ll,double rr): L (LL), R (RR) {};}; vector<node>node[maxd];void Debug (int v) {if (!v) {puts (""); return;} Debug (V/2); printf ("%d", v% 2);} BOOL Judge (int S) {for (int i = 0; i < n; i++) if (S = = (1 << i)) return true; return false;} void Dfs (int S) {///enumerate the subsets of now if (Vis[s]) return; Vis[s] = 1; if (judge (S)) {Node[s].push_back (node (0,0)); Return }//printf ("%d\n", S); for (int S0 = S; S0; S0 = (s0-1) & S) if (S0! = s) {int l = S0; int r = S0 ^ S; DFS (L); DFS (R); Enumerates the left and right subsets for (int i = 0; i < node[l].size (), i++) for (int j = 0; J < node[r].size (); Double L1 = 1.0 * SUM[R]/(Sum[l] + sum[r]); Double R1 = 1.0 * Sum[l]/(Sum[l] + sum[r]); Double L2 = min (-l1 + node[l][i].l,r1 + node[r][j].l); Double r2 = max (-l1 + node[l][i].r,r1 + NODE[R][J].R); printf ("[%d]:%.2f%.2f\n", S,L2,R2); Node[s].push_back (Node (L2,R2)); }} return; int main () {int T; scanf ("%d", &t); while (t--) {scanf ("%lf%d", &ww,&n); ret =-1; memset (vis,0,sizeof (VIS)); for (int i = 0; i < n; i++) scanf ("%d", &w[i]); for (int i = 0; i < (1 << n); i++) {sum[i] = 0; Node[i].clear (); for (int j = 0;j < N; j + +) {if (I & (1 << j)) {Sum[i] + = w[j]; }}} int S = (1 << N)-1; DFS (S); printf ("%d\n", Node[s].size ()); for (int i = 0; i < node[s].size (); i++) {Double d = NODE[S][I].R-NODE[S][I].L; printf ("%.4f%.4f\n", NODE[S][I].R,NODE[S][I].L); if (d <= ww) ret = max (ret,d); } if (Ret < 0) printf (" -1\n"); else printf ("%.16f\n", ret); } return 0;}
1354Mobile Computing (brute force, binary enumeration, simply heartless)