首页 > 其他分享 >[CF1229E]Marek and Matching

[CF1229E]Marek and Matching

时间:2023-09-22 20:45:26浏览次数:32  
标签:Marek le return 10 int CF1229E LL 1LL Matching

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));
}

标签:Marek,le,return,10,int,CF1229E,LL,1LL,Matching
From: https://www.cnblogs.com/mekoszc/p/17723322.html

相关文章

  • 【ERROR: Could not find a version that satisfies】【ERROR: No matching distribut
    pip包安装出错真是把我烦死了,在yt上学东西,结果一直出这样的错,之前我都是把包下载到本地安装的,这也不是长久之计。然后我试了使用-i,使用--trusted-host,使用--user,使用--upgradepip...全都不管用。后来我想,究竟是什么时候出现这个问题的,好像很久之前就有了...老提示不安全的连......
  • Transformer-empowered Multi-scale Contextual Matching and Aggregation for
    Transformer-empoweredMulti-scaleContextualMatchingandAggregationforMulti-contrastMRISuper-resolution(阅读文献)10.12基于变压器的磁共振多对比度超分辨率多尺度背景匹配与聚合摘要:MRI可以显示相同解剖结构的多对比图像,使多对比超分辨率(SR)技术成为可能。和使用单一......
  • [VLDB 2012]Efficient Subgraph Matching on Billion Node Graphs
    [VLDB2012]EfficientSubgraphMatchingonBillionNodeGraphs重点了解实现star-join的具体过程。分解query和STwigs排序文中把star叫做STwigs,每一个STwigs查询为\(q=(r,L)\),其中r是跟节点标签,L是子节点标签合集。点的选择性:\(f(v)=deg(v)/freq(v.label)\)分解算法:每次......
  • 解决error: no matching member for call to 'connect'
    在连接信号与槽时,报错解决error:nomatchingmemberforcallto'connect'原因由于信号被重载过,同名了,但是参数不一样,就会报错。这种情况下使用使用旧版语法connect(sender,SIGNAL(func()),receiver,SLOT(func1()))......
  • [VLDBJ 2019]Distributed Subgraph Matching on Timely Dataflow
    [VLDBJ2019]DistributedSubgraphMatchingonTimelyDataflow只关注这篇中的subgraphmatching的内容定义\(g=(V_g,E_g,L_g)\)分别表示点、边,以及把任意点或边映射成label的函数。如果是无标签图则会映射为空。对于任意点\(\mu\inV_g\),定义\(N_g(\mu)\)为它的邻居节......
  • springboot加载bean失败:No matching autowired candidates found
    场景:之前在培训轮岗,一直没有干活,最近开始干活遇到xxljob,打算自己学习了解一下。在按照文档配置执行器项目时,发现怎么启动,xxlJobExecutor都没有被加载进来。解决:后来经过查阅,原来是springBoot启动默认扫描的是启动类所在的包以及其子包,而我的文件为:因此bean注入失败。把......
  • [ABC318D] General Weighted Max Matching 题解
    [ABC318D]GeneralWeightedMaxMatching题解题意  给定无向有权完全图,求最大权匹配。思路分析  注意到\(n\le16\),我考虑状压DP。  设当前点集\(S\)中最大权匹配的答案是\(f_S\),我们考虑\(S\)中“最后”一个点\(p\)(这里的“最后”一个点是指,在状压表示状态......
  • vscode高亮插件Highlight Matching Tag的样式设置
    vscode高亮插件HighlightMatchingTag的样式设置HighlightMatchingTag插件下载安装后,一般不会立即显示,需要在setting.json文件上加上一段代码,才有高亮显示。高亮样式设计参考插件官网:https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag。......
  • [CEOI2011] Matching 题解
    [CEOI2011]Matching题解题外话:看了其他人题解后作为初学$kmp$的我非常蒙,因为对这个算法的核心掌握不太好,不知道怎么维护动态的序列,因此写下此题解共享经验,建议只会打模板的看看。参考资料:https://www.cnblogs.com/fusiwei/p/11944975.html思路引导:看到数据范围,又和真实......
  • P9562 [SDCPC2023] G-Matching
    思路易发现,如果\(i\)和\(j\)可以连边,\(j\)和\(k\)可以连边,那\(i\)和\(k\)也可以连边,如果\(x\)不能和\(i\)连边,那\(x\)同样不能和\(j,k\)连边。所以我们可以考虑把所有可以连边的放在一起,这样就把所有点分成了若干部分,并且每个部分不可能连边,必然是分割开的。......