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
#include <bits/stdc++.h>
using namespace std;

long long n, m, p, res;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> p;
	
	long long dp[n+5][m+5][m+5] = {};
	
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= m-i+1; j++)
			dp[1][i][j] = 1;
	
	for (int i = 1; i < n; i++)
		for (int j = 1; j <= m; j++)
			for (int k = 1; k <= m-j+1; k++)
				for (int j2 = 1; j2 <= j+k-1; j2++)
					for (int k2 = max(1, j-j2+1); k2 <= m-j2+1; k2++)
							dp[i+1][j2][k2] = (dp[i+1][j2][k2] + dp[i][j][k]) % p;
			
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= m-i+1; j++)
			res = (res + dp[n][i][j]) % p;
	
	cout << res << '\n';
}