Problem
Mean
在一个n轮状基中删去若干条边,使得各点之间有且仅有一条通路。
Analysis
递推公式 f[i]=f[i-1]*3-f[i-2]+2
正解是基尔霍夫矩阵,然而我并不知道这是什么东西……
(我是小数据模拟一波然后找规律的)
Code
#include<cstdio>
int n;
struct BigInt{
static const int BASE=10000,WIDTH=4;
int s[200];
BigInt(int num=0){*this=num;}
BigInt operator = (int &num){
s[0]=0;
while(num){
s[++s[0]]=num%BASE;
num/=BASE;
}
return *this;
}
BigInt operator * (const int &num) const {
BigInt c;
c.s[0]=0;
for(int i=1,g=0;;i++){
if(i>s[0] && !g) break;
int x=g;
if(i<=s[0]) x+=s[i]*num;
c.s[++c.s[0]]=x%BASE;
g=x/BASE;
}
return c;
}
BigInt operator - (const BigInt &b) {
BigInt c;
c.s[0]=s[0];
for(int i=1;i<=s[0];i++){
if(i<=b.s[0]){
if(s[i]<b.s[i]) s[i]+=BASE,s[i+1]-=1;
c.s[i]=s[i]-b.s[i];
}else{
if(s[i]<0) s[i]+=BASE,s[i+1]-=1;
c.s[i]=s[i];
}
}
while(!c.s[c.s[0]] && c.s[0]) c.s[0]--;
return c;
}
BigInt operator + (const int &num) const {
BigInt c;
for(int i=0;i<=s[0];i++) c.s[i]=s[i];
c.s[1]+=num;
int p=1;
if(c.s[p]>=BASE){
c.s[p+1]=c.s[p]/=BASE;
c.s[p++]%=BASE;
}
if(p>c.s[0]) c.s[0]=p;
return c;
}
};
BigInt f[105];
int main(){
f[1]=1,f[2]=5;
scanf("%d",&n);
for(int i=3;i<=n;i++)
f[i]=f[i-1]*3-f[i-2]+2;
printf("%d",f[n].s[f[n].s[0]]);
for(int i=f[n].s[0]-1;i>0;i--) printf("%04d",f[n].s[i]);
return 0;
}