问题描述: | 转眼到了2008年的6月9日,盼望已久的高考结束了。我们踏上了向西的旅程(本来是想写 西去之路,可是考虑不太妥当)。可可西里,多么诱人的名词,充满了奇幻的色彩和自然的 淳朴。从可可西里徒步走回家的决定是在1年半前定下的,而现在,终于可以实现那个钩过 手指的预定。我们的可可西里。。。 | |
数据输入: | 一个整数N 代表藏羚羊的个数 | |
结果输出: | 一个整数sum代表方法数 | |
样例: | 4 | 9 |
核心思想: | 类似于求的组合数,运用到了高精乘单精,还有边长为奇数和偶数方案数是有规律的 |
var
n:longint;
f:array[0..1001,0..2001] of longint;
len:array[0..1001] of longint;
procedure cheng(x,t:longint);{<高精乘单精>}
var
i,jw:longint;
begin
jw:=0;
fori:=1 to len[x-1] do
begin
ifi=1 then f[x,i]:=f[x-1,i]*x+t+jw {<在第一位上处理t,因为t做的是加法>}
else f[x,i]:=f[x-1,i]*x+jw;
jw:=f[x,i] div 10000;
f[x,i]:=f[x,i] mod 10000;
end;
len[x]:=len[x-1];
while jw<>0 do{<处理最高位是否有进位>}
begin
inc(len[x]);
f[x,len[x]]:=jw mod 10000;
jw:=jw div 10000;
end;
end;
procedure main;
var
i,t:longint;
begin
len[1]:=1; f[1,1]:=0;{<len是高精度数f[]的长度,f[第一维]表示边长为()的矩阵的方案数>}
len[2]:=1; f[2,1]:=1;
fori:=3 to n do{<加一圈所增加的方案数>}
begin
ifi mod 2=0 then t:=1 else t:=-1;{<要判定奇偶,奇数时两个角是不能放的>}
cheng(i,t);
end;
write(f[n,len[n]]);
fori:=len[n]-1 downto 1 do
begin
iff[n,i]<1000 then write(0);
iff[n,i]<100 then write(0);
iff[n,i]<10 then write(0);
write(f[n,i]);
end;
end;
begin
assign(input,'p1254.in');reset(input);
assign(output,'p1254.out');rewrite(output);
readln(n);
main;
close(input);close(output);
end.
题目来源:NDK 1254