This is a harder version of the problem. In this version, \(n \le 7\).

Marek is working hard on creating strong test cases to his new algorithmic problem. Do you want to know what it is? Nah, we're not telling you. However, we can tell you how he generates test cases.

Marek chooses an integer \(n\) and \(n^2\) integers \(p_{ij}\) (\(1 \le i \le n\), \(1 \le j \le n\)). He then generates a random bipartite graph with \(2n\) vertices. There are \(n\) vertices on the left side: \(\ell_1, \ell_2, \dots, \ell_n\), and \(n\) vertices on the right side: \(r_1, r_2, \dots, r_n\). For each \(i\) and \(j\), he puts an edge between vertices \(\ell_i\) and \(r_j\) with probability \(p_{ij}\) percent.

It turns out that the tests will be strong only if a perfect matching exists in the generated graph. What is the probability that this will occur?

It can be shown that this value can be represented as \(\frac{P}{Q}\) where \(P\) and \(Q\) are coprime integers and \(Q \not\equiv 0 \pmod{10^9+7}\). Let \(Q^{-1}\) be an integer for which \(Q \cdot Q^{-1} \equiv 1 \pmod{10^9+7}\). Print the value of \(P \cdot Q^{-1}\) modulo \(10^9+7\).

\(n\le 7\),是一个很暴力的范围。

但是怎么暴力?

我们在搜索的过程中,如何很好的维护出最大匹配的信息?

考虑维护每一个左端点集合是否存在最大匹配,然后每次新增一个左端点,枚举这个点能到的集合,设为 \(s\),可以预处理出概率。然后再更新那些有最大匹配的概率。复杂度明显是爆的。

略微优化一下搜索过程,在搜索时处理出这个左端点如果连到了点 \(i\) 会有哪些最大匹配改变,可以用 __int128 状压,记为 \(f_i\)。然后枚举对应的集合时可以直接把所有 \(f_j(j\in s)\) 或起来就可以了。

可以考虑记忆化,用一个状压记录每个集合是否有最大匹配(状压的状压?有点绕)。然后就过了。记录的时候可以用一个 __int128 记到 map 里面,然后就可以过了。

#include<bits/stdc++.h>
using namespace std;
typedef unsigned __int128 LL;
const int N=10,P=1e9+7,S=1<<N;
int pown(int x,int y)
{
if(!y)
return 1;
int t=pown(x,y>>1);
if(y&1)
return 1LL*t*t%P*x%P;
return 1LL*t*t%P;
}
int n,p[N][N],f[N][S],cnt;
map<LL,int>mp[N];
LL mx;
void write(LL x)
{
if(!x)
return;
write(x/10);
putchar(x%10+48);
}
int dfs(int x,LL s)
{
/*printf("%d ",x),write(s);
puts("");*/
if(x==n)
{
return s==mx;
}
if(mp[x].find(s)!=mp[x].end())
return mp[x][s];
++cnt;
LL f[N];
for(int i=0;i<n;i++)
f[i]=0;
int ans=0;
for(int i=0;i<(1<<n);i++)
{
if(s>>i&1)
for(int k=0;k<n;k++)
f[k]|=((LL)1)<<(i|(1<<k));
}
for(int i=1;i<(1<<n);i++)
{
LL to=s;
for(int j=0;j<n;j++)
if(i>>j&1)
to|=f[j];
ans+=dfs(x+1,to)*1LL*::f[x][i]%P;
if(ans>=P)
ans-=P;
}
return mp[x][s]=ans;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<(1<<n);i++)
mx|=((LL)1)<<i;
int pw=pown(100,P-2);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",p[i]+j),p[i][j]=1LL*p[i][j]*pw%P;
for(int i=0;i<n;i++)
{
for(int j=0;j<(1<<n);j++)
{
f[i][j]=1;
for(int k=0;k<n;k++)
{
if(j>>k&1)
f[i][j]=1LL*f[i][j]*p[k][i]%P;
else
f[i][j]=1LL*f[i][j]*(1+P-p[k][i])%P;
}
}
}
printf("%d",dfs(0,1));
}

[CF1229E]Marek and Matching的更多相关文章

  1. Codeforces Round #588 (Div. 1) 简要题解

    1. 1229A Marcin and Training Camp 大意: 给定$n$个对$(a_i,b_i)$, 要求选出一个集合, 使得不存在一个元素好于集合中其他所有元素. 若$a_i$的二进制 ...

  2. 学习《Hardware-Efficient Bilateral Filtering for Stereo Matching》一文笔记。

    个人收藏了很多香港大学.香港科技大学以及香港中文大学里专门搞图像研究一些博士的个人网站,一般会不定期的浏览他们的作品,最近在看杨庆雄的网点时,发现他又写了一篇双边滤波的文章,并且配有源代码,于是下载下 ...

  3. LeetCode题解-----Wildcard Matching

    题目描述: '?' Matches any single character. '*' Matches any sequence of characters (including the empty ...

  4. cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.

    spring 配置文件报错报错信息:cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be ...

  5. [LeetCode] Wildcard Matching 外卡匹配

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...

  6. [LeetCode] Regular Expression Matching 正则表达式匹配

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  7. Beginning Scala study note(5) Pattern Matching

    The basic functional cornerstones of Scala: immutable data types, passing of functions as parameters ...

  8. ios 关于问题 no matching provisioning profiles found

    ios 关于问题 no matching provisioning profiles found

  9. iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)

    从2月14日开始,上传程序的同学可能会遇到提示上传失败的提示. 并且打开自己的钥匙串,发现所有的证书全部都显示此证书签发者无效. 出现以下情况: Failed to locate or generat ...

  10. ORA-12516:TNS:listener could not find available handler with matching protocol stack

    应用程序连接测试数据库时报ORA-12516:TNS:listener could not find available handler with matching protocol stack 检查 ...

随机推荐

  1. VScode软件的安装以及C/C++环境配置的方法

    今天和大家分享一下VScode软件的安装以及C/C++环境配置的方法.手把手教大家入门. 1,下载VScode编译器 (1)    官网下载链接:https://code.visualstudio.c ...

  2. c++算法:二分

    算法中,有一种比线性查找算力费得更少的一种算法思想,叫"分治",今天讲的是分治里的二分查找: 借助 (low+high)/2公式,找到搜索区域内的中间元素.图 1 中,搜索区域内中 ...

  3. 按关键字API接口搜索天眼查企业数据

    一.如果你想要查找某一个企业的基本信息或是对行业中的企业进行筛选,那么使用API接口搜索天眼查企业数据会非常方便. 首先,你需要获取天眼查API的access_token,这可以通过注册账号获取.一旦 ...

  4. (洛谷P4213)杜教筛

    https://www.cnblogs.com/Mychael/p/8744633.html #pragma GCC optimize(3, "Ofast", "inli ...

  5. Xshell7 / Xftp7 永久免费,官网直连下载地址

    主要目的是让大家随时随地从官网下载Xshell和Xftp免费版(个人/家庭/学校免费) 最新变动:官方目前仅提供最新版以及上一个版本的软件下载!其他版本不提供下载 免费版5版本(最后一个版本,无任何限 ...

  6. Ds100p -「数据结构百题」21~30

    21.P4172 [WC2006]水管局长 SC 省 MY 市有着庞大的地下水管网络,嘟嘟是 MY 市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从 \(x ...

  7. Spring-Boot-Starter 学习笔记(1)

    Spring-Boot-Starter 1. 准备配置类和 Bean 对象 Spring Boot 提供了两个注解: @Configuration:Spring 提供的配置类注解,作用在类上,代表整个 ...

  8. 浅析依赖属性(DependencyProperty)

    在WPF中,引入了依赖属性这个概念,提到依赖属性时通常都会说依赖属性能节省实例对内存的开销.此外依赖属性还有两大优势. 支持多属性值,依赖属性系统可以储存多个值,配合Expression.Style. ...

  9. 洛谷题解 | P1046 陶陶摘苹果

    ​ 目录 题目描述 输入格式 输出格式 输入输出样例 说明/提示 题目思路 AC代码 题目描述 陶陶家的院子里有一棵苹果树,每到秋天树上就会结出 10 个苹果.苹果成熟的时候,陶陶就会跑去摘苹果.陶陶 ...

  10. Python面试——基础面试题

    文章目录 1.Python 和 Java.PHP.C.C#.C++等其他语言的对比? C语言既有高级语言的特点,又具有汇编语言的特点,它是结构式语言.C语言应用指针:可以直接进行靠近硬件的操作,但是C ...