Problem:
Score : 1200 points

Problem Statement

Find the number of the possible tuples of sequences (A_0,A_1,...,A_N) that satisfy all of the following conditions, modulo M:

For every i (0\leq i\leq N), A_i is a sequence of length i consisting of integers between 1 and K (inclusive);

For every i (1\leq i\leq N), A_{i-1} is a subsequence of A_i, that is, there exists 1\leq x_i\leq i such that the removal of the x_i-th element of A_i would result in a sequence equal to A_{i-1};

For every i (1\leq i\leq N), A_i is lexicographically larger than A_{i-1}.

Constraints

1 \leq N,K \leq 300

2 \leq M \leq 10^9

N, K and M are integers.

Input

Input is given from Standard Input in the following format:

N K M

Output

Print the number of the possible tuples of sequences (A_0,A_1,...,A_N), modulo M.

Sample Input 1

2 2 100

Sample Output 1

5

Five tuples below satisfy the conditions:

(),(1),(1,1)

(),(1),(1,2)

(),(1),(2,1)

(),(2),(2,1)

(),(2),(2,2)

Sample Input 2

4 3 999999999

Sample Output 2

358

Sample Input 3

150 150 998244353

Sample Output 3

186248260

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 305;
int dp[N][N], pref[N][N], C[N][N], n, k, m;

signed main(){
    scanf("%lld %lld %lld", &n, &k, &m);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            if (i == 0 || j == 0 || i == j) C[i][j] = 1;
            else C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % m;
        }
    }

    memset(dp, 0, sizeof(dp));

    for (int i = 1; i <= k + 1; i++) {
        dp[1][i] = 1;
        if (i == 1) pref[1][i] = dp[1][i];
        else pref[1][i] = (pref[1][i - 1] + dp[1][i]) % m;
    }

    for (int i = 2; i <= n + 1; i++) {
        for (int j = 1; j <= k + 1; j++) {
            for (int p = 1; p <= i - 1; p++) {
                int res = C[i - 2][p - 1];
                res *= dp[p][j]; res %= m;
                res *= pref[i - p][j - 1]; res %= m;

                dp[i][j] = (dp[i][j] + res) % m;
            }

            if (j == 1) pref[i][j] = dp[i][j];
            else pref[i][j] = (pref[i][j - 1] + dp[i][j]) % m;
        }
    }

    printf("%lld", dp[n + 1][k + 1]);
    return 0;
}