#include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef LOCAL #define debug(...) __VA_ARGS__ #else #define debug(...) {} #endif int wy[10001][10001]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int i; int n,m,p; cin>>m>>n>>p; for (i = 1; i < n+1; i++) for (int j = i; j < n+1; j++) wy[i][j] = 1; int pre[n+2]; int suf[n+2]; for (int k1 = 1; k1 < m; k1++){ for (i = 0; i < n+2; i++) pre[i] = suf[i] = 0; for (i = 1; i < n+1; i++){ for (int j = i; j < n+1; j++){ pre[j] = (pre[j]+wy[i][j])%p; suf[i] = (suf[i]+wy[i][j])%p; } } for (i = 1; i < n+1; i++){ pre[i] = (pre[i]+pre[i-1])%p; //cout<<pre[i]<<" "; } // cout<<"\n"; for (i = n; i ; i--){ suf[i] = (suf[i]+suf[i+1])%p; //cout<<suf[i]<<" "; } //cout<<"\n"; for (i = 1; i < n+1; i++){ for (int j = i; j < n+1; j++){ wy[i][j] = (pre[n]+(-pre[i-1]-suf[j+1]+2*p)%p)%p; } } //return 0; } int endwy = 0; for (i = 1; i < n+1; i++) for (int j = i; j < n+1; j++) endwy = (endwy+wy[i][j])%p; cout<<endwy%p<<"\n"; return 0; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef LOCAL #define debug(...) __VA_ARGS__ #else #define debug(...) {} #endif int wy[10001][10001]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int i; int n,m,p; cin>>m>>n>>p; for (i = 1; i < n+1; i++) for (int j = i; j < n+1; j++) wy[i][j] = 1; int pre[n+2]; int suf[n+2]; for (int k1 = 1; k1 < m; k1++){ for (i = 0; i < n+2; i++) pre[i] = suf[i] = 0; for (i = 1; i < n+1; i++){ for (int j = i; j < n+1; j++){ pre[j] = (pre[j]+wy[i][j])%p; suf[i] = (suf[i]+wy[i][j])%p; } } for (i = 1; i < n+1; i++){ pre[i] = (pre[i]+pre[i-1])%p; //cout<<pre[i]<<" "; } // cout<<"\n"; for (i = n; i ; i--){ suf[i] = (suf[i]+suf[i+1])%p; //cout<<suf[i]<<" "; } //cout<<"\n"; for (i = 1; i < n+1; i++){ for (int j = i; j < n+1; j++){ wy[i][j] = (pre[n]+(-pre[i-1]-suf[j+1]+2*p)%p)%p; } } //return 0; } int endwy = 0; for (i = 1; i < n+1; i++) for (int j = i; j < n+1; j++) endwy = (endwy+wy[i][j])%p; cout<<endwy%p<<"\n"; return 0; } |