[NDK 安置诸侯]

[题目来源]:2011/11/04模拟赛

[关键字]:递推

[题目大意]:在一个类似菱形的地图里放置诸侯,保证每一行每一列都只有一个诸侯。

//=====================================================================================================

[分析]:先把地图转化成,再用递推。可以很容易的求出方程:f[i,j]=∑f[k,j-1]*(l[i]-(j-1))其中f[i,j]为前i列放j个,l[i]是第i列有多少个。

[代码]:

View Code
 1 {$i-,s-,q-,r-}
2 var
3 ans, k, n, i, j, m, temp: longint;
4 f: array[0..200,0..200] of longint;
5
6 function min(x, y: longint):longint;
7 begin
8 if x < y then exit(x) else exit(y);
9 end;
10
11 procedure print(x: longint);
12 begin
13 writeln(x);
14 halt;
15 end;
16
17 begin
18 readln(n,m);
19 if m = 0 then print(1);
20 if m >= 2*n-1 then print(0);
21 fillchar(f,sizeof(f),0);
22 f[0,0] := 1;
23 for i := 1 to n do
24 if odd(i) then f[i,1] := i else f[i,1] := i-1;
25 for i := 1 to 2*n-1 do
26 begin
27 if odd(i) then temp := i else temp := i-1;
28 for j := 2 to min(i,m) do
29 for k := j-1 to i-1 do
30 f[i,j] := (f[i,j]+f[k,j-1]*(temp-j+1)) mod 504;
31 end;
32 for i := m to 2*n-1 do ans := (ans+f[i,m]) mod 504;
33 print(ans);
34 end.



你可能感兴趣的:(NDK)