1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define double long double
//#define mod 1000000007ll
#define INF 1000000000000000000ll

int dp[4][1010][20];
int ty[4][1010][20];
int wyn[1010][20];

int dwumian[1010][1010];
int N, K, mod;

void init() {
    for( int n=0; n<=1000; n++ ) {
        dwumian[n][0] = 1;
        dwumian[n][n] = 1;
        for( int k=1; k<n; k++ ) {
            dwumian[n][k] = (dwumian[n-1][k-1] + dwumian[n-1][k])%mod;
        }
    }
}

int res( int n, int k ) {
    if( k>10 ) return 0;
    return (wyn[n][k]-wyn[n][k-1]+mod)%mod;
}

int32_t main() {
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );

    cin >> N >> K >> mod;
    init();

    for( int i=0; i<4; i++ ) {
        //dp[i][0][0] = 1;
        for( int k=0; k<20; k++ ) {
            dp[i][0][k] = 1;
        }
    }
    for( int n=1; n<=1005; n++ ) {
        for( int k=1; k<=11; k++ ) {
            for( int j=1; j<=n; j++ ) {
                dp[3][n][k] = (dp[3][n][k] + (dp[3][j-1][k]*dp[3][n-j][k]-ty[3][j-1][k]*ty[3][n-j][k]+mod*mod)%mod*dwumian[n-1][j-1])%mod;
            }
            ty[3][n][k] = (dp[3][n][k]-dp[3][n][k-1]+mod)%mod;

            for( int j=1; j<=n; j++ ) {
                dp[2][n][k] = (dp[2][n][k] + (dp[3][j-1][k-1]*dp[2][n-j][k])%mod*dwumian[n-1][j-1])%mod;
            }
            ty[2][n][k] = (dp[2][n][k]-dp[2][n][k-1]+mod)%mod;
        }
    }

    for( int n=0; n<=1005; n++ ) {
        for( int k=0; k<=11; k++ ) {
            for( int j=1; j<=n; j++ ) {
                wyn[n][k] = (wyn[n][k] + dp[2][j-1][k]*dp[2][n-j][k]%mod*dwumian[n-1][j-1])%mod;
            }
        }
    }

    /*int x=0;
    for( int i=1; i<=1000; i++ ) {
        for( int j=1; j<=1000; j++ ) {
            x = (x + i*j*res(i, j))%mod;
        }
    }
    cout << x << "\n";*/

    cout << res( N, K );
    //cout << dp[0][N][K]

    return 0;
}/*
1 1 100000007
*/