bzoj 1002 找规律(基尔霍夫矩阵)

时间:2023-03-09 00:27:58
bzoj 1002 找规律(基尔霍夫矩阵)

  网上说的是什么基尔霍夫矩阵,没学过这个,打个表找下规律,发现

w[i]=3*w[i-1]-w[i-2]+2;

然后写个高精直接递推就行了

//By BLADEVIL
var
n :longint;
a, b, c :array[..] of longint;
w :array[..] of ansistring;
i :longint; function plus(s1,s2:ansistring):ansistring;
var
len :longint;
i :longint;
s :ansistring; begin
fillchar(a,sizeof(a),);
fillchar(b,sizeof(b),);
fillchar(c,sizeof(c),);
len:=length(s1);
for i:= to len do a[(len-i) div +]:=a[(len-i) div +]*+ord(s1[i])-;
len:=length(s2);
for i:= to len do b[(len-i) div +]:=b[(len-i) div +]*+ord(s2[i])-;
if length(s1)>len then len:=length(s1);
len:=(len+) div ;
for i:= to len do
begin
c[i]:=c[i]+a[i]+b[i];
c[i+]:=c[i+]+c[i] div ;
c[i]:=c[i] mod ;
end;
inc(len);
plus:='';
for i:=len downto do
begin
str(c[i],s);
if c[i]< then plus:=plus+'';
if c[i]< then plus:=plus+'';
if c[i]< then plus:=plus+'';
plus:=plus+s;
end;
while (plus[]='') and (length(plus)>) do delete(plus,,);
end; function jian(s1,s2:ansistring):ansistring;
var
len :longint;
i :longint;
s :ansistring;
begin
fillchar(a,sizeof(a),);
fillchar(b,sizeof(b),);
fillchar(c,sizeof(c),);
len:=length(s1);
for i:= to len do a[(len-i) div +]:=a[(len-i) div +]*+ord(s1[i])-;
len:=length(s2);
for i:= to len do b[(len-i) div +]:=b[(len-i) div +]*+ord(s2[i])-;
len:=(length(s1)+) div ;
for i:= to len do c[i]:=a[i]-b[i];
for i:= to len do if c[i]< then
begin
c[i]:=c[i]+;
dec(c[i+]);
end;
jian:='';
for i:=len downto do
begin
str(c[i],s);
if c[i]< then jian:=jian+'';
if c[i]< then jian:=jian+'';
if c[i]< then jian:=jian+'';
jian:=jian+s;
end;
while (jian[]='') and (length(jian)>) do delete(jian,,);
end; begin
read(n);
w[]:=''; w[]:='';
for i:= to n do
w[i]:=plus(jian(plus(plus(w[i-],w[i-]),w[i-]),w[i-]),'');
writeln(w[n]);
end.