xsyProblem A: 密集子图(graph)
- 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)的更多相关文章
- hdu 3879 最大密集子图(点和边均带权)(模板)
/* 最大权闭合图,可以用最大密集子图来解速度更快复杂度低 题解:胡伯涛<最小割模型在信息学竞赛中的应用> 点和边均带权的最大密集子图 s-i,权为U=点权绝对值和+边的所有权值 i-t, ...
- poj 3155 二分+最小割求实型最小割(最大密集子图)
/* 最大密集子图子图裸题 解法:设源点s和汇点t 根据胡波涛的<最小割模型在信息学中的应用> s-每个点,权值为原边权和m, 每个点-t,权值为m+2*g-degree[i], 原来的边 ...
- 最大密集子图(01分数规划+二分+最小割)POJ3155
题意:给出一副连通图,求出一个子图令g=sigma(E)/sigma(V); h[g]=sigma(E)-g*sigma(V):设G是最优值 则当h[g]>0:g<G h[g]<0, ...
- 大规模SNS中兴趣圈子的自动挖掘
转自:http://www.infoq.com/cn/articles/zjl-sns-automatic-mining 一.为何要在大规模SNS中挖掘兴趣圈子 随着国外的facebook.twitt ...
- dot 语法全介绍
0. 保存 保存为 pdf:dot -Tpdf iris.dot -o iris.pdf 1. 基本 (1)无向图.有向图.子图 graph G {} // 无向图 digraph G {} // 有 ...
- noip模拟27[妹子图·腿·腰](fengwu半仙的妹子们)
\(noip模拟27\;solutions\) 这次吧,我本来以为我能切掉两个题,结果呢??只切掉了一个 不过,隔壁Varuxn也以为能切两个,可惜了,他一个都没切...... 确实他分比我高一点,但 ...
- py2neo学习记录
py2neo 通用 # -*- coding: UTF-8 -*- from py2neo import Graph, Node, Relationship, walk, NodeMatcher, R ...
- codeforces 1082G - Petya and Graph 最大权闭合子图 网络流
题意: 让你选一些边,选边的前提是端点都被选了,求所有的边集中,边权和-点权和最大的一个. 题解: 对于每个边建一个点,然后就是裸的最大权闭合子图, 结果比赛的时候我的板子太丑,一直T,(不会当前弧优 ...
- Factor Graph因子图
参考链接1: 参考链接2: 参考ppt3: Factor Graph 是概率图的一种,概率图有很多种,最常见的就是Bayesian Network (贝叶斯网络)和Markov Random Fiel ...
随机推荐
- python url 下载并保存
方法一:用urllib import jsonimport urllib url_model='{"version":"2","url":& ...
- 微服务-开发框架之springboot by 大雄daysn
目录 一.关于springboot 二.springboot的实践 2.1发布一个rest的api 2.2端点 2.3健康检查 2.4远程监控 一.关于springboot 由来:spring1.0- ...
- 论坛短信息(JSP项目)
if("list".equals(action)){ String username = request.getSession().getAttribute("login ...
- 不得不补:PHP的JSON, SQL
不管怎么说,还是得感谢慕课网,提供了很多免费的视频教学. 学习自: https://www.imooc.com/view/68 前端页面: <!DOCTYPE html> <html ...
- TensorFlow 神经网络相关函数
TensorFlow 激活函数 激活操作提供用于神经网络的不同类型的非线性.这些包括平滑的非线性(sigmoid,tanh,elu,softplus,和softsign),连续的,但不是到处可微函数( ...
- python 使用jinjia2 生成文件的空格处理
例如: <div> {% if True %} yay {% endif %} </div> 生成文件为 <div> yay </div> 两种方法解决 ...
- quora 的东西就是不一样
Coding is just a part of process of problem solving, You should need to understand the underlying pr ...
- clearfix 用法
如果有一个DIV作为外部容器,内部的DIV如果设置了float样式,则外部的容器DIV因为内部没有 clear,导致不能被撑开.看下面的例子:Div布局如下:Css代码如下:.out{border:1 ...
- hdu 6241 Color a Tree 2017 CCPC 哈理工站 L
Bob intends to color the nodes of a tree with a pen. The tree consists of NN nodes. These nodes are ...
- Git版本库创建(包含文件权限设置 Linux环境下)
确保git服务已安装成功,如果没有安装git服务查看:Git源码安装 Linux指定安装目录 1.创建git用户,并设置密码.并禁止git用户通过shell登录服务器(注意如果需要安装gitolite ...