forked from tmwilliamlin168/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPECTAC.cpp
More file actions
34 lines (30 loc) · 738 Bytes
/
SPECTAC.cpp
File metadata and controls
34 lines (30 loc) · 738 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=50;
int n, m, k, M;
ll dp[mxN+1][mxN+1][mxN+1], dp2[mxN+1][mxN+1];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k >> M;
dp[0][0][0]=1;
for(int a=1; a<=n; ++a) {
memset(dp2, 0, (a+1)*sizeof(dp2[0]));
for(int b=1; b<=a; ++b) {
for(int c=1; c<=b; ++c) {
for(int d=a; d<=n; ++d) {
for(int e=m; e; --e) {
dp[a][c][e]=(dp[b-1][c-1][e-1]+dp[a][c][e-1]+dp[a][c][e])%M;
if(d>a)
dp2[c][e]=(dp[b-1][c-1][e-1]+dp2[c][e-1]+dp2[c][e])%M;
}
}
}
}
for(int b=0; b<=a; ++b)
for(int c=0; c<=m; ++c)
dp[a][b][c]=(dp[a][b][c]-dp2[b][c]+M+dp[a-1][b][c])%M;
}
cout << dp[n][k][m];
}