#include <bits/stdc++.h>
using namespace std;
long long n,m,p,ans;
vector <char> x[10];
void plot (int i, int l, int r)
{
/* x[i-1].resize(m);
for (int j=1; j<l; j++)
x[i-1][j]='.';
for (int j=l; j<=r; j++)
x[i-1][j]='X';
for (int j=r+1; j<=m; j++)
x[i-1][j]='.';*/
if (i==n+1)
{
/*(for (int j=1; j<=m; j++)
{
for (int k=1; k<=n; k++)
cout<< x[k][j];
cout<< '\n';
}
cout<< "\n";*/
ans++;
if (ans>=p)
ans%=p;
return;
}
for (int j=1; j<l; j++)
for (int k=l; k<=m; k++)
if (j<=k)
plot(i+1, j, k);
for (int j=l; j<=r; j++)
for (int k=l; k<=m; k++)
if (j<=k)
plot(i+1, j, k);
}
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>> n>> m>> p;
plot (1,1,m);
cout<< ans;
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 50 51 52 | #include <bits/stdc++.h> using namespace std; long long n,m,p,ans; vector <char> x[10]; void plot (int i, int l, int r) { /* x[i-1].resize(m); for (int j=1; j<l; j++) x[i-1][j]='.'; for (int j=l; j<=r; j++) x[i-1][j]='X'; for (int j=r+1; j<=m; j++) x[i-1][j]='.';*/ if (i==n+1) { /*(for (int j=1; j<=m; j++) { for (int k=1; k<=n; k++) cout<< x[k][j]; cout<< '\n'; } cout<< "\n";*/ ans++; if (ans>=p) ans%=p; return; } for (int j=1; j<l; j++) for (int k=l; k<=m; k++) if (j<=k) plot(i+1, j, k); for (int j=l; j<=r; j++) for (int k=l; k<=m; k++) if (j<=k) plot(i+1, j, k); } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>> n>> m>> p; plot (1,1,m); cout<< ans; return 0; } |
English