• f[i][S]三进制压缩表示最长路为i,0代表不在该集合,1代表不是最短路为i集合,2代表是最短路集合, 转移枚举i+1集合是那些, 乘以概率即可
  • 预处理保证复杂度

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define mmp make_pair
#define M 13
#define N 610000
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
const int mod = 998244353;
void add(int &x, int y) {
x += y;
x -= x >= mod ? mod : 0;
}
int mul(int a, int b) {
return 1ll * a * b % mod;
} int poww(int a, int b) {
int ans = 1, tmp = a;
for(; b; b >>= 1, tmp = mul(tmp, tmp)) if(b & 1) ans = mul(ans, tmp);
return ans;
}
int n, k, note[M][M], q[4100][4100], f[M][N], g[N], h[N], u, pw[M], cnt; int main() {
n = read(), k = read();
u = (1 << (n - 1)) - 1;
for(int i = 0; i <= n; i++) pw[i] = (1 << i);
for(int i = 1; i <= (n * (n - 1)); i++) {
int vi = read(), vj = read(), p = read(), q = read();
note[vi][vj] = mul(p, poww(q, mod - 2));
}
for(int i = 0; i <= u; i++) {
for(int j = 0; j <= u; j++) {
if((i | j) == i) {
q[i][j] = ++cnt;
int s = (i ^ j), t = j;
g[cnt] = h[cnt] = 1;
for(int r = 2; r <= n; ++r)
if(t & pw[r - 2]) {
int p = 1;
for(int l = 2; l <= n; l++) {
if(s & pw[l - 2]) p = mul(p, (1 - note[l][r] + mod) % mod);
}
g[cnt] = mul(g[cnt], (1 - p + mod));
h[cnt] = mul(h[cnt], p);
h[cnt] = mul(h[cnt], (1 - note[1][r] + mod));
}
}
}
}
for(int s = 0; s <= u; s++) {
f[1][q[s][s]] = 1;
for(int i = 2; i <= n; i++) if(s & pw[i - 2]) f[1][q[s][s]] = mul(f[1][q[s][s]], note[1][i]);
}
for(int i = 1; i < k; i++) {
for(int s = 0; s <= u; s++) {
for(int now = s; now; now = (now - 1) & s) {
if(!f[i][q[s][now]]) continue;
for(int t = (u ^ s); t; t = (t - 1) & (u ^ s)) {
add(f[i + 1][q[s | t][t]], mul(mul(f[i][q[s][now]], g[q[now | t][t]]), h[q[(now ^ s) | t][t]]));
}
}
}
}
int ans = 0;
for(int i = 1; i <= k; i++)
for(int s = 0; s <= u; s++) add(ans, f[i][q[u][s]]);
cout << ans <<"\n";
return 0;
}

xsyProblem A: 密集子图(graph)的更多相关文章

  1. hdu 3879 最大密集子图(点和边均带权)(模板)

    /* 最大权闭合图,可以用最大密集子图来解速度更快复杂度低 题解:胡伯涛<最小割模型在信息学竞赛中的应用> 点和边均带权的最大密集子图 s-i,权为U=点权绝对值和+边的所有权值 i-t, ...

  2. poj 3155 二分+最小割求实型最小割(最大密集子图)

    /* 最大密集子图子图裸题 解法:设源点s和汇点t 根据胡波涛的<最小割模型在信息学中的应用> s-每个点,权值为原边权和m, 每个点-t,权值为m+2*g-degree[i], 原来的边 ...

  3. 最大密集子图(01分数规划+二分+最小割)POJ3155

    题意:给出一副连通图,求出一个子图令g=sigma(E)/sigma(V); h[g]=sigma(E)-g*sigma(V):设G是最优值 则当h[g]>0:g<G h[g]<0, ...

  4. 大规模SNS中兴趣圈子的自动挖掘

    转自:http://www.infoq.com/cn/articles/zjl-sns-automatic-mining 一.为何要在大规模SNS中挖掘兴趣圈子 随着国外的facebook.twitt ...

  5. dot 语法全介绍

    0. 保存 保存为 pdf:dot -Tpdf iris.dot -o iris.pdf 1. 基本 (1)无向图.有向图.子图 graph G {} // 无向图 digraph G {} // 有 ...

  6. noip模拟27[妹子图·腿·腰](fengwu半仙的妹子们)

    \(noip模拟27\;solutions\) 这次吧,我本来以为我能切掉两个题,结果呢??只切掉了一个 不过,隔壁Varuxn也以为能切两个,可惜了,他一个都没切...... 确实他分比我高一点,但 ...

  7. py2neo学习记录

    py2neo 通用 # -*- coding: UTF-8 -*- from py2neo import Graph, Node, Relationship, walk, NodeMatcher, R ...

  8. codeforces 1082G - Petya and Graph 最大权闭合子图 网络流

    题意: 让你选一些边,选边的前提是端点都被选了,求所有的边集中,边权和-点权和最大的一个. 题解: 对于每个边建一个点,然后就是裸的最大权闭合子图, 结果比赛的时候我的板子太丑,一直T,(不会当前弧优 ...

  9. Factor Graph因子图

    参考链接1: 参考链接2: 参考ppt3: Factor Graph 是概率图的一种,概率图有很多种,最常见的就是Bayesian Network (贝叶斯网络)和Markov Random Fiel ...

随机推荐

  1. 【转载】在线yml与properties文件转换工具

    http://www.toyaml.com/index.html

  2. 通过进程link路径(快捷方式路径)得到进程完整路径

    程序中遇到的问题及解决方法: #error WINDOWS.H already included. MFC apps must not #include <windows.h>解决方法:把 ...

  3. [转] Ubuntu16.04完美安装Sublime text3

    转载自:https://www.cnblogs.com/hupeng1234/p/6957623.html 1.安装方法 1)使用ppa安装 sudo add-apt-repository ppa:w ...

  4. 判断手机是安卓还是ios

    let ORZ = function() { if(!(this instanceof ORZ)) { return new ORZ; }}ORZ.prototype = { // 判断用户手机是An ...

  5. 搭建数据驱动框架第一步-实现一个构造函数,将对Excel文件的基本操作API都封装进去

    Python处理Excel常用操作就是读和写,我的需求是需要在原excel文件中进行读写操作.共用到了两个模块xlrd和openpyxl,这两个模块都是需要自己去安装的.openpyxl只能用来处理 ...

  6. 关于attibutedText输出中文字符后的英文和数字进行分开解析的问题

    上面的图应该很清楚 具体这个attibutedText 是做什么的就不说了 ,最初我查了资料发现有人和我一样的输出,把一个字符串的中英文分开打印出来是iOS关于UItextVIew和UIlabel的差 ...

  7. AFN\HTTPS\UIWebView

    1.AFN使用技巧 1.在开发的时候可以创建一个工具类,继承自我们的AFN中的请求管理者,再控制器中真正发请求的代码使用自己封装的工具类. 2.这样做的优点是以后如果修改了底层依赖的框架,那么我们修改 ...

  8. des加密破解

    在爬取某些网站时, 登录等重要操作的返回结果是des加密后的. 如何破解 1, Python 语言采用 pyDes 作为 DES 加解密处理的包. 2,通过请求 http://tool.chacuo. ...

  9. https加载非https资源时不出现问题

    老规矩,国服第一博客copy王,原文链接:https://blog.csdn.net/zhengbingmei/article/details/81325325将系统变成了https访问之后,发现部分 ...

  10. 我的代码-data pulling

    # coding: utf-8 import datetimeimport timefrom sqlalchemy.engine import create_enginefrom sqlalchemy ...