一位一位考虑异或结果, f(x)表示x->n异或值为1的概率, 列出式子然后高斯消元就行了

------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
 
using namespace std;
 
typedef long double ld;
#define b(i) (1 << (i))
 
const int maxn = 109;
 
ld mat[maxn][maxn];
int N, deg[maxn];
 
struct edge {
int to, w;
edge* next;
} E[20009], *pt = E, *head[maxn];
 
void AddEdge(int u, int v, int w) {
deg[pt->to = v]++; pt->w = w; pt->next = head[u]; head[u] = pt++;
}
 
void Init() {
memset(deg, 0, sizeof deg);
int m;
scanf("%d%d", &N, &m); N--;
for(int i = 0; i < m; i++) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
u--; v--;
AddEdge(u, v, w);
if(u != v) AddEdge(v, u, w);
}
}
 
void Work() {
for(int i = 0; i < N; i++) {
int r = i;
for(int j = i; ++j < N; )
if(fabs(mat[j][i]) > fabs(mat[r][i])) r = j;
if(r != i) {
for(int j = 0; j <= N; j++)
swap(mat[i][j], mat[r][j]);
}
for(int j = i; ++j < N; ) {
ld t = mat[j][i] / mat[i][i];
for(int k = i; k <= N; k++)
mat[j][k] -= t * mat[i][k];
}
}
for(int i = N; i--; ) {
for(int j = i; ++j < N; ) 
mat[i][N] -= mat[i][j] * mat[j][N];
mat[i][N] /= mat[i][i];
}
}
 
int main() {
Init();
ld ans = 0;
for(int i = 0; i < 30; i++) {
memset(mat, 0, sizeof mat);
for(int j = 0; j < N; j++) {
for(edge* e = head[j]; e; e = e->next) if(e->to != N) {
if(e->w & b(i))
mat[j][e->to]--, mat[j][N]--;
else
mat[j][e->to]++;
} else if(e->w & b(i))
mat[j][N]--;
mat[j][j] -= deg[j];
}
Work();
ans += mat[0][N] * b(i);
}
printf("%.3lf\n", (double) ans);
return 0;
}

------------------------------------------------------------------

2337: [HNOI2011]XOR和路径

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 699  Solved: 390
[Submit][Status][Discuss]

Description

Input

Output

Sample Input

Sample Output

HINT

Source

BZOJ 2337: [HNOI2011]XOR和路径( 高斯消元 )的更多相关文章

  1. BZOJ 2337: [HNOI2011]XOR和路径 [高斯消元 概率DP]

    2337: [HNOI2011]XOR和路径 题意:一个边权无向连通图,每次等概率走向相连的点,求1到n的边权期望异或和 这道题和之前做过的高斯消元解方程组DP的题目不一样的是要求期望异或和,期望之间 ...

  2. BZOJ2337:[HNOI2011]XOR和路径(高斯消元)

    Description 给定一个无向连通图,其节点编号为 1 到 N,其边的权值为非负整数.试求出一条从 1 号节点到 N 号节点的路径,使得该路径上经过的边的权值的“XOR 和”最大.该路径可以重复 ...

  3. BZOJ2337: [HNOI2011]XOR和路径(高斯消元,期望)

    解题思路: Xor的期望???怕你不是在逗我. 按为期望,新技能get 剩下的就是游走了. 代码: #include<cmath> #include<cstdio> #incl ...

  4. 【概率DP/高斯消元】BZOJ 2337:[HNOI2011]XOR和路径

    2337: [HNOI2011]XOR和路径 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 682  Solved: 384[Submit][Stat ...

  5. bzoj 2337 [HNOI2011]XOR和路径【高斯消元+dp】

    首先,我们发现,因为是无向图,所以相连的点之间是有"依赖性"的,所以不能直接用dp求解. 因为是xor,所以按位处理,于是列线性方程组,设$ x[i] $为点i到n异或和为1的期望 ...

  6. BZOJ 2337 XOR和路径 | 高斯消元 期望 位运算

    BZOJ 2337 XOR和路径 题解 这道题和游走那道题很像,但又不是完全相同. 因为异或,所以我们考虑拆位,分别考虑每一位: 设x[u]是从点u出发.到达点n时这一位异或和是1的概率. 对于所有这 ...

  7. bzoj 2337: [HNOI2011]XOR和路径

    Description Input Output Sample Input Sample Output HINT Source Day2 终于把这个史前遗留的坑给填了... 首先异或的话由位无关性,可 ...

  8. ●BZOJ 2337 [HNOI2011]XOR和路径

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2337题解: 概率dp, 因为异或的每一位之间没有关系,我们就依次考虑每一位k.(即边权要么为 ...

  9. BZOJ 2337 [HNOI2011]XOR和路径 ——期望DP

    首先可以各位分开求和 定义$f(i)$表示从i到n的期望值,然后经过一些常识,发现$f(n)=1$的时候的转移,然后直接转移,也可以找到$f(n)=0$的转移. 然后高斯消元31次就可以了. #inc ...

随机推荐

  1. mysql binlog 混合模式 出现的基于sql的数据不一致,主要是now()这类函数导致

  2. openstack 升级设计要求的指导原则

    不知道其他软件有没有类似的指导原则. Theory of Upgrade Grenade works under the following theory of upgrade. New code s ...

  3. nfs nobody,nobody 需要在nfs客户端修改从nfs服务器端共享过来的目录怎么办?

    1,加入我们使用nfs共享安装oracle, 安装oracle需要修改base,data,orainventory等等目录及自目录的属主及权限,一般会继承nfs客户端目录的权限及属主 groupadd ...

  4. findOneAndUpdate的用法详解

    Fragment.findOneAndUpdate({_id:id}, {$set: datas}, {upsert:true, 'new':true}).populate('ads').exec(f ...

  5. Swift初体验(三)

    /*******************************************************************************/ // 协议 protocol Des ...

  6. Tiny Spring 分析一

    近期一直想看spring的源代码,可是奈何水平太低,庞杂的源代码令我一阵阵的头晕. 非常有幸,在网上看到了黄亿华大神的<<1000行代码读懂Spring(一)- 实现一个主要的IoC容器& ...

  7. 电商网站前端架构#1 多页面 vs 单页面

    课程地址:http://www.imooc.com/learn/186 讲师:远人 课程基础: html css js ,做过一些项目. 多页面 我们往常使用的web服务大多是多页面形式,依靠后端的架 ...

  8. js中字符串方法

    字符串方法: 1. charAt(索引值)//通过索引值获取字符串中对应的值 例如: var str='sdf123'; alert(str.charAt(0));//结果弹出第一个索引对应的值:s

  9. 3n+1

    #include<iostream> using namespace std; int main() { int n; while(cin>>n) { int count=0; ...

  10. aJax学习之Ajax工作原理

    转自:http://www.cnblogs.com/mingmingruyuedlut/archive/2011/10/18/2216553.html 在写这篇文章之前,曾经写过一篇关于AJAX技术的 ...