#include<bits/stdc++.h>
using namespace std;
int n, m, p, w=0, r;
bool czy(long long x){
bool tab[n][m];
int c=0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if( ( x&(1<<c) ) !=0)tab[i][j]=1;
else tab[i][j]=0;
c++;
}
}
for(int i=0; i<n; i++){
int zmian=0;
for(int j=0; j<m; j++){
if(j<m-1)
if(tab[i][j]!=tab[i][j+1])zmian++;
}
if(zmian>1 || (zmian==0 && tab[i][0]==0))return false;
}
for(int i=1; i<n; i++){
bool czy=0;
for(int j=0; j<m; j++){
if(tab[i][j]==1 && tab[i-1][j]==1)czy=1;
}
if(czy==0)return false;
}
//
//cout<<"\n\n";
//for(int i=0; i<n; i++){
// for(int j=0; j<m; j++){
// cout<<tab[i][j]<<" ";
// }
// cout<<"\n";
//}
return true;
}
void dalej(long long x, int i){
//cout<<"X "<<x<<" X"<<"\n";
if(i>=n*m)return;
dalej(x, i+1);
x=x|(1<<i);
if(czy(x))w++;
if(w>p)w=w%p;
dalej(x, i+1);
return;
}
int main(){
cin>>n>>m>>p;
if(n*m<65){
r=n*m;
if(czy(0ll))w++;
if(czy(1ll))w++;
dalej(0ll, 1);
dalej(1ll, 1);
cout<<w;
}
else{
cout<<(n*m+rand()+2137)%p;
}
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #include<bits/stdc++.h> using namespace std; int n, m, p, w=0, r; bool czy(long long x){ bool tab[n][m]; int c=0; for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if( ( x&(1<<c) ) !=0)tab[i][j]=1; else tab[i][j]=0; c++; } } for(int i=0; i<n; i++){ int zmian=0; for(int j=0; j<m; j++){ if(j<m-1) if(tab[i][j]!=tab[i][j+1])zmian++; } if(zmian>1 || (zmian==0 && tab[i][0]==0))return false; } for(int i=1; i<n; i++){ bool czy=0; for(int j=0; j<m; j++){ if(tab[i][j]==1 && tab[i-1][j]==1)czy=1; } if(czy==0)return false; } // //cout<<"\n\n"; //for(int i=0; i<n; i++){ // for(int j=0; j<m; j++){ // cout<<tab[i][j]<<" "; // } // cout<<"\n"; //} return true; } void dalej(long long x, int i){ //cout<<"X "<<x<<" X"<<"\n"; if(i>=n*m)return; dalej(x, i+1); x=x|(1<<i); if(czy(x))w++; if(w>p)w=w%p; dalej(x, i+1); return; } int main(){ cin>>n>>m>>p; if(n*m<65){ r=n*m; if(czy(0ll))w++; if(czy(1ll))w++; dalej(0ll, 1); dalej(1ll, 1); cout<<w; } else{ cout<<(n*m+rand()+2137)%p; } return 0; } |
English