bzoj4894(矩阵树定理)

外向树的计数。。

计外向树时只要把基尔霍夫矩阵的定义改一下就可以了。。

把对角线定义为该点的入度,然后减去有向图的邻接矩阵就可以了。。

然后把根所在的行列去掉求行列式即可。。

 

 

 

/*
 *        ┏┓    ┏┓
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃  
 *        ┃   ━    ┃
 *        ┃ >   < ┃
 *        ┃       ┃
 *        ┃... ⌒ ...  ┃
 *        ┃       ┃
 *        ┗━┓   ┏━┛
 *          ┃   ┃ Code is far away from bug with the animal protecting          
 *          ┃   ┃   神兽保佑,代码无bug
 *          ┃   ┃           
 *          ┃   ┃        
 *          ┃   ┃
 *          ┃   ┃           
 *          ┃   ┗━━━┓
 *          ┃       ┣┓
 *          ┃       ┏┛
 *          ┗┓┓┏━┳┓┏┛
 *           ┃┫┫ ┃┫┫
 *           ┗┻┛ ┗┻┛
 */
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 305
#define nm 100005 
#define pi 3.1415926535897931
using namespace std;
const ll inf=1e9+7;
int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
 






int n;
ll a[NM][NM];
char _s[NM];

ll det(){
    ll ans=1;
    inc(i,2,n)inc(j,i+1,n){
	for(int x=i,y=j;a[y][i];swap(x,y)){
	    ll t=a[x][i]/a[y][i];
	    inc(k,i,n)a[x][k]+=inf-t*a[y][k]%inf,a[x][k]%=inf;
	}
	if(!a[i][i]){
	    ans=-ans;
	    inc(k,i,n)swap(a[i][k],a[j][k]);
	}
    }
    inc(i,2,n)ans*=a[i][i],ans%=inf;ans+=inf;ans%=inf;
    //inc(i,1,n){inc(j,1,n)printf("%lld ",a[i][j]);putchar('\n');}
    return ans;
}

int main(){
    n=read();
    inc(i,1,n){
	scanf("%s",_s+1);
	inc(j,1,n)a[i][j]-=_s[j]-'0';
    }
    inc(i,1,n)inc(j,1,n)if(i!=j)a[i][i]-=a[j][i];
    //inc(i,1,n){inc(j,1,n)printf("%lld ",a[i][j]);putchar('\n');}putchar('\n');
    return 0*printf("%lld\n",det());
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值