[BZOJ4894]天赋

bzoj

sol

矩阵树定理裸题
其实可以不用辗转相除直接乘逆元就好了。然而我还是写的辗转相除

code

#include<cstdio>
#include<algorithm>
using namespace std;
int gi()
{
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N = 305;
const int mod = 1e9+7;
int n,a[N][N],ans=1;char s[N][N];
int main()
{
	n=gi();
	for (int i=1;i<=n;++i)
	{
		scanf("%s",s[i]+1);
		for (int j=1;j<=n;++j)
			if (s[i][j]=='1') a[i][j]--,a[j][j]++;
	}
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j)
			a[i][j]=(a[i][j]+mod)%mod;
	for (int i=2;i<=n;++i)
	{
		for (int j=i+1;j<=n;++j)
			while (a[j][i])
			{
				int t=a[i][i]/a[j][i];
				for (int k=i;k<=n;++k) a[i][k]=(a[i][k]-1ll*t*a[j][k]%mod+mod)%mod,swap(a[i][k],a[j][k]);
				ans=(mod-ans)%mod;
			}
		ans=1ll*ans*a[i][i]%mod;
	}
	printf("%d\n",ans);return 0;
}
posted @ 2018-04-21 10:28  租酥雨  阅读(145)  评论(0编辑  收藏  举报