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. 数仓备份经验分享丨详解roach备份原理及问题处理套路

    本文分享自华为云社区<GaussDB(DWS) 备份问题定位思路>,作者: yd_216390446. 前言 在数据库系统中,故障分为事务内部故障.系统故障.介质(磁盘)故障.对于事务内部 ...

  2. # Unity 如何获取Texture 的内存大小

    Unity 如何获取Texture 的内存大小 在Unity中,要获取Texture的内存文件大小,可以使用UnityEditor.TextureUtil类中的一些函数.这些函数提供了获取存储内存大小 ...

  3. 【Ubuntu】Ubuntu 配置记录

    目录 系统文件夹改回英文 Ubuntu 镜像 pypi 镜像 临时使用 设为默认 Doxygen + Graphviz 分析代码并画图 Graphviz 安装 Doxygen 安装 配置 运行 系统文 ...

  4. Ascend C保姆级教程:我的第一份Ascend C代码

    本文分享自华为云社区<Ascend C保姆级教程:我的第一份Ascend C代码>,作者:昇腾CANN . Ascend C是昇腾AI异构计算架构CANN针对算子开发场景推出的编程语言,原 ...

  5. WPF MVVM之点滴分享

    (第五点:绑定源有修改) 我并不打算长篇累牍的介绍什么是MVVM.我尽量简洁的介绍,并把自己的经验分享给大家. 一.关于MVVM M:Model,数据模型(后台存储数据的类) V:View,视图(大部 ...

  6. C# Wke例子 -- WebUI登录窗口

    概述 Wke介绍: http://blog.csdn.net/sabrecode/article/details/78145938 用Wke做了一个登录窗口, webui比较特殊. 因为它就是一个超文 ...

  7. Vue用v-bind给标签属性赋值 src, href...

    给属性渲染数据不能使用 {{name}} 标记, 请使用 v-bind:属性名称="name" name是json数据键值对中的键名, 请配合下面JS代码片食用 HTML < ...

  8. HTML视频背景(动态背景)

    网页动态背景一般是用视频实现的,能增添网页的感染力,我觉得很好看,也不难,不妨学一下. 先加入下面一串代码: 1 <style> 2 video{ 3 height: 100%; 4 wi ...

  9. Longest Divisors Interval

    Smiling & Weeping ----总有一个人, 一直住在心底, 却消失在生活里. Given a positive integer n, find the maximum size ...

  10. 使用docker搭建seafile服务器

    工作需要在单位和家里的不同电脑上同步指定文件夹及其内容.对比了一些解决方案,最终还是选择熟悉的seafile来做. 需要按照官方文档进行seafile的安装,选择官方推荐的docker方式快速部署. ...