skyscrapers/Skyscrapers_artur.java
1 import java.util.Scanner;
2
3 public class Skyscrapers_artur {
4
5 static final int MAXN = 5010;
6 static final int mod = 1000000007;
7 static final long[][] c = new long[MAXN][MAXN];
8 static final long[][] s = new long[MAXN][MAXN];
9
10 public static void main(String[] args) {
11 Scanner in = new Scanner(System.in);
12
13
14 c[0][0] = 1;
15 for (int i = 1; i < c.length; i++)
16 for (int j = 0; j <= i; j++)
17 c[i][j] = ((j > 0 ? c[i - 1][j - 1] : 0) + c[i - 1][j]) % mod;
18
19 while (true) {
20 int n = in.nextInt();
21 int a = in.nextInt();
22 int b = in.nextInt();
23
24 if (n == 0 && a == 0 && b == 0)
25 break;
26
27
28
29 s[0][0] = 1;
30 for (int i = 1; i <= n; i++)
31 for (int j = 1; j <= i; j++)
32
33
34
35
36
37 s[i][j] = (s[i - 1][j - 1] + (i - 1) * s[i - 1][j]) % mod;
38
39 long result = 0;
40 for (int k = 0; k < n; k++)
41
42
43
44
45
46 result = (result + c[n - 1][k] * s[k][a - 1] % mod * s[n - k - 1][b - 1]) % mod;
47 System.out.println(result);
48 }
49 }
50 }