Pascal编程(JSOI)

来源:百度知道 编辑:UC知道 时间:2024/06/11 01:02:33
1、蜜蜂路线(work1.pas)
[问题描述]
一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房M开始爬到蜂房N,M<N<30000,有多少种爬行路线?

如输入:1 14
则输出:377

2、3×2n的骨牌问题(work2.pas)
[问题描述]
已知3×2n个棋盘格子,试求用火柴棒覆盖所有格子的方法(一根火柴棒可覆盖2个格子)。
如n=1时,有如下3种覆盖方法:
输入:n
输出:用火柴棒覆盖所有3×2n格子的方案数。
输入样例:1
输出样例:3
Think you~(最好给出程序~)

program work1;{实际上就是求斐波那契数列}
const maxn=10000;
type sz=array[1..maxn] of byte;
var a,b,c:sz;
{}{}i,j,m,n,lena,lenb,l:integer;
procedure add(var a,b,c:sz);{高精度加法,等价于c=a+b;a=b;b=c}
var i:integer;
begin
{}if lena>lenb then l:=lena else l:=lenb;
{}for i:=1 to l do c[i]:=a[i]+b[i];
{}for i:=1 to l do
{}{}if c[i]>=10 then
{}{}{}begin
{}{}{}{}c[i]:=c[i]-10;
{}{}{}{}c[i+1]:=c[i+1]+1;
{}{}{}end;
{}if c[l+1]>0 then l:=l+1;
{}a:=b;lena:=lenb;b:=c;lenb:=l;
end;

begin
{} readln(m,n);
{} if m>n then exit
{}{} else if n-m=1 then writeln(1)
{}{}{} else
{}{}{} begin
{}{}{}{}{}a[1]:=1;b[1]:=1; lena:=1;lenb:=1;l:=0;
{}{}{}{}{}for i:=3 to n-m+1 do
{}{}{}{}{}{}add(a,b,c);
{}{}{}{}{}for i:=l downto 1 do write(c[i]);
{}{}{} end;
end.
__________________________________________________________

program work2; {f(n)=4f(n-1)-f(n-