bzoj1002: [FJOI2007]轮状病毒
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1002
这题呢考试的时候我估计我只能打表找规律了,规律找不找得出来还是另一回事。
可以得到如下递推式,F(n) = 3 * F(n-1) - F(n-2) + 2 其中 F(1) = 1, F(2) = 5
如果想看证明的同学可以到http://vfleaking.blog.163.com/blog/static/17480763420119685112649/
然后高精度就行了
代码:
1 program xx; 2 var a:array[0..120,0..100] of longint; 3 i,j,k,n,m,p,q,r:longint; 4 begin 5 readln(n); 6 for i:=1 to n do 7 a[i,1]:=1; 8 a[2,1]:=5; 9 for i:=3 to n do 10 begin 11 for j:=1 to 80 do 12 a[i,j]:=a[i-1,j]*3-a[i-2,j]; 13 a[i,1]:=a[i,1]+2; 14 for k:=1 to j do 15 if a[i,k]<0 16 then 17 begin 18 a[i,k]:=a[i,k]+10; 19 dec(a[i,k+1]); 20 end 21 else 22 begin 23 a[i,k+1]:=a[i,k] div 10+a[i,k+1]; 24 a[i,k]:=a[i,k] mod 10; 25 end; 26 end; 27 i:=100; 28 while a[n,i]=0 do dec(i); 29 for j:=i downto 1 do 30 write(a[n,j]); 31 end.