BZOJ2337: [Hnoi2011]xor and path

Source: Internet
Author: User
Description

Input Output Sample Input Sample Output HINT It is more difficult to solve the above problem directly by Source . This 23333 is more difficult to randomize well, since it is different or so bitwise contribution can then be dp[i] means that I to n the path of this one on the 1 probability of high chaos can be

#include <bits/stdc++.h> using namespace std;
const int MAXN = 110;
const int MAXM = 20020;

Const double EPS = 1e-9;

int n, m;

Double P[MAXN][MAXN], ANS[MAXN], ret;
		inline void Gauss () {for (int i = 1; I <= n; i++) {int t = i;
		for (int j = i + 1; j <= N; j + +) if (Fabs (p[j] [i]) > fabs (p[t [i] + eps)) t = j;
		for (int j = i; J <= n + 1; j + +) swap (p[I [j], p[T] [j]);
			for (int j = i + 1; j <= N; j + +) {Double t = p[j] [i]/p[I [i];
		for (int k = i; k <= n + 1; k++) p[J [K]-= p[I [k] * t;
		for (int i = n; i; i--) {Double cur = p[I] [n + 1];
		for (int j = i + 1; j <= N; j + +) cur-= p[I [j] * ans[J];
	ans[i] = cur/p[I [i]; } struct Edge {int to, NXT, Val;}

e[MAXM];

int HEAD[MAXN], CNT, D[MAXN]; inline void Addedge (int x, int y, int w) {e[++cnt].to = y; e[cnt].nxt = head[x]; head[x] = cnt; e[cnt].val = W ;
D[y]++; int main () {SCANF ("%d%d", &n, &m);
		for (int i = 1; I <= m; i++) {int x, y, W;
		scanf ("%d%d%d", &x, &y, &w);
		Addedge (x, Y, W);
	if (x ^ y) addedge (y, X, W);
		for (int i = 0; I <= i++) {memset (ans, 0, sizeof (ans));
		memset (p, 0, sizeof (p));
			for (int x = 1; x <= n-1 x + +) {p[x] [x] =-1;  for (int j = head[x]; j; j = e[J].nxt) {if (e[J].val >> i) & 1 p[x] [n + 1] = 1.0/d[
				X], p[x] [e[j].to]-= 1.0/d[x];
			else p[x] [e[j].to] + = 1.0/d[x];
		} p[n [n] = 1;
		Gauss ();
	RET + + (1 << i) * ans[1];
return printf ("%.3lf\n", ret), 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.