# BZOJ1002

7 篇文章 0 订阅

Kirchhoff Matrix Tree定理：
G $G$为无向图，取E$E$为图 G $G$的度数矩阵，F$F$为图 G $G$的邻接矩阵

R=n111111310011131001030100111013n+1

Q=310001131000030000011100013n

Q(n)=3×G(n1)2×G(n2)2

310000131000030000011000013n

G(n)=3×G(n1)G(n2)

ans=3×G(n1)2×G(n2)2

G(n)=383×G(n1)G(n2)n=1n=2otherwise

【吐槽：题解LaTeX代码写的时间比我做题时间还长】

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

struct node
{
int a[1100],l;
node()
{
memset(a,0,sizeof(a));
l = 1;
}
friend inline node operator *(int x,node &y)
{
node ret; ret.l = y.l+1;
for (int i = 1;i <= y.l;++i)
{
ret.a[i] += y.a[i]*x;
ret.a[i+1] += ret.a[i]/10;
ret.a[i] %= 10;
}
if (ret.a[ret.l] == 0) ret.l--;
return ret;
}
friend inline node operator -(node x,node y)
{
node z; z.l = max(x.l,y.l);
for (int i = 1;i <= z.l;++i)
{
z.a[i] = x.a[i]-y.a[i];
while (z.a[i] < 0)
z.a[i] += 10,x.a[i+1]--;
}
while (z.l > 1&&z.a[z.l] == 0)z.l--;
return z;
}
friend inline node operator +(node &x,int y)
{
node ret = x;
ret.a[1] += y;
for (int i = 1;i <= ret.l;++i)
{
if (ret.a[i] >= 10)
ret.a[i]-=10,ret.a[i+1]++;
else break;
}
if (ret.a[ret.l+1]) ret.l++;
return ret;
}
inline void print()
{
for (int i = l;i >= 1;--i)
printf("%d",this->a[i]);
}
};

int n;
node g[110];
node ans;

{
freopen("loli.in","r",stdin);
scanf("%d",&n);
}

void Solve()
{
g[1]=g[1]+3;
g[2]=g[2]+8;
if(n<=2){
g[n].print();
return;
}
for(int i=3;i<=n;i++)
g[i]=3*g[i-1]-g[i-2];
ans=3*g[n-1]-2*g[n-2];
ans=ans+(-2);
ans.print();
}

void Close()
{
fclose(stdin);
fclose(stdout);
}

int main()

{
Solve();
Close();
}
• 2
点赞
• 0
收藏
觉得还不错? 一键收藏
• 1
评论
10-14 117
12-06 245
02-04 405
05-11 447
12-18 361
04-06 591
08-27 332
09-03 990
09-06 594
03-18 450

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