E. Omkar and Forest——Codeforces Round #724 (Div. 2)

Posted 出尘呢

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E. Omkar and Forest——Codeforces Round #724 (Div. 2)相关的知识,希望对你有一定的参考价值。

https://codeforces.com/contest/1536/problem/E

Imagine picking some subset of ‘#’ and making them 0. Then there is exactly one way to make all the remaining ‘#’ positive integers.
——官方题解

这句话非常重要。
就是,让若干的#为0,每次这样选都会有一种符合解(因为多源BFS)。所以我们只要看有多少种不同的让若干#为0即可。
计#个数为n,则选取方式如下:

C n 0 + C n 1 + . . . + C n n C^0_n+C^1_n+...+C^n_n Cn0+Cn1+...+Cnn
通过高中知识,这个结果是
2 n 2^n 2n
(但是其实我也是看大佬的qwq)
https://blog.csdn.net/qq_41286356/article/details/105788449

https://blog.csdn.net/litble/article/details/75913032?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2

1.情景假设法(假设boshi从枣树选枣子的方案。。。)
2.隔板法(boshi把枣子放成一排,通过在枣子间添加隔板来分组。。。)
3.通向公式法
4.递推公式法

这里相当于n个中选0~n个的所有情况,所有情况即每个有选与不选两种情况。
或者: ( 1 + 1 ) n = C n 0 + C n 1 + . . . + C n n (1+1)^n=C^0_n+C^1_n+...+C^n_n (1+1)n=Cn0+Cn1+...+Cnn是显然的

但是如果整个图全是#,没有0,没有BFS源,要除掉-1即可,因为没有0只有一种情况,就是整个图全是#时选0个#取0。

AC代码:

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define int long long
char a[2005];
inline int qp(int a,int n,int mod)
	int ans=1;
	while(n)
		if(n&1)ans=ans*a%mod;
		a=a*a%mod;
		n>>=1;
	
	return ans;

signed main()
	int t;
	scanf("%lld",&t);
	int n,m;
	while(t--)
		scanf("%lld%lld",&n,&m);
		int cnt=0;
		for(int i=0;i<n;i++)
			scanf("%s",a);
			for(int j=0;j<m;j++)
				if(a[j]=='#')cnt++;
			
		
		int te=qp(2,cnt,MOD);
		te-=cnt==m*n;
		printf("%lld\\n",te);
	
	return 0;

以上是关于E. Omkar and Forest——Codeforces Round #724 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

E. Omkar and Forest 思维,结论

Codeforces Round #724 (Div. 2)1536E - Omkar and Forest(思维,结论)

D. Omkar and Circle

[Codeforces 1586] Omkar and Determination | 思维前缀和

Codeforces Round #655 (Div. 2) A. Omkar and Completion

E. 1-Trees and Queries