Link : SKYLINE
Category :Maths
Solution : Recurrence works out to be Catalan number.
Code:
Category :Maths
Solution : Recurrence works out to be Catalan number.
Code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cat:array[1..1001] of int64; | |
var n:longint; | |
const md:int64=1000000; | |
procedure prep(); | |
var i,j:longint; | |
var tmp:int64; | |
begin | |
cat[1]:=1; | |
for i:=2 to 1001 do begin | |
cat[i]:=0; | |
for j:=1 to i-1 do begin | |
tmp:=(cat[j]*cat[i-j]) mod md; | |
cat[i]:=cat[i]+tmp; | |
end; | |
cat[i]:=cat[i] mod md; | |
end; | |
end; | |
begin | |
prep(); | |
while true do begin | |
readln(n); | |
if n=0 then break; | |
writeln(cat[n+1]); | |
end; | |
end. |
No comments:
Post a Comment