#include<bits/stdc++.h>
using namespace std;
long long dp[10][10];
long long dp2[10][10];
int tab[10];
bool intersect(int a,int b,int c,int d)
{
if(c>=a && c<=b)
return true;
if(d>=a && d<=b)
return true;
if(a>=c && a<=d)
return true;
if(b>=c && b<=d)
return true;
return false;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a,b,mod;
cin>>b>>a>>mod;
for(int x=0;x<a;x++)
for(int y=x;y<a;y++)
dp[x][y] = 1;
for(int x=1;x<b;x++)
{
for(int i=0;i<a;i++)
for(int j=i;j<a;j++)
for(int k=0;k<a;k++)
for(int l=k;l<a;l++)
if(intersect(i,j,k,l))
dp2[i][j] += dp[k][l];
for(int i=0;i<a;i++)
for(int j=i;j<a;j++)
{
dp[i][j] = dp2[i][j]%mod;
dp2[i][j] = 0;
}
}
long long sum = 0;
for(int x=0;x<a;x++)
for(int y=x;y<a;y++)
sum+=dp[x][y];
cout<<sum%mod;
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 | #include<bits/stdc++.h> using namespace std; long long dp[10][10]; long long dp2[10][10]; int tab[10]; bool intersect(int a,int b,int c,int d) { if(c>=a && c<=b) return true; if(d>=a && d<=b) return true; if(a>=c && a<=d) return true; if(b>=c && b<=d) return true; return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a,b,mod; cin>>b>>a>>mod; for(int x=0;x<a;x++) for(int y=x;y<a;y++) dp[x][y] = 1; for(int x=1;x<b;x++) { for(int i=0;i<a;i++) for(int j=i;j<a;j++) for(int k=0;k<a;k++) for(int l=k;l<a;l++) if(intersect(i,j,k,l)) dp2[i][j] += dp[k][l]; for(int i=0;i<a;i++) for(int j=i;j<a;j++) { dp[i][j] = dp2[i][j]%mod; dp2[i][j] = 0; } } long long sum = 0; for(int x=0;x<a;x++) for(int y=x;y<a;y++) sum+=dp[x][y]; cout<<sum%mod; return 0; } |
English