-
Notifications
You must be signed in to change notification settings - Fork 3
/
k_nice.cpp
executable file
·46 lines (44 loc) · 1.33 KB
/
k_nice.cpp
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
#include <fstream>
#include <vector>
using namespace std;
int n,m;
void ability (vector<vector<bool>> &a){
for (int i=0; i<a.size(); i++)
for (int j=0; j<a.size(); j++)
for (int k=0; k<n-1; k++) if ((i >> k) % 2 == (i >> (k + 1)) % 2) {
if (((i >> k) % 2 == 1) && ((j >> k) % 2 == 1) && ((j >> (k + 1)) % 2 == 1)) a[i][j] = false;
else if (((i >> k) % 2 == 0) && ((j >> k) % 2 == 0) && ((j >> (k + 1)) % 2 == 0)) a[i][j] = false;
}
}
void base(vector<vector<int>> &a){
for (int i=0; i<a[0].size(); i++) a[0][i]=1;
}
int main() {
ifstream fin("nice.in");
ofstream fout("nice.out");
fin >> n >> m;
if (n>m) {
int t=n;
n=m;
m=t;
}
if ((n==1) && (m==1)) fout << 2;
else {
vector<vector<int>> dp(m, vector<int> (1<<n, 0));
vector<vector<bool>> can((1<<n), vector<bool> (1<<n, true));
ability(can);
base(dp);
int sum=0;
for (int i=1; i<dp.size(); i++)
for (int j=0; j<(1<<n); j++)
for (int k=0; k<(1<<n); k++){
if (can[k][j]) {
dp[i][j]+=dp[i-1][k];
if (i==dp.size()-1) sum+=dp[i-1][k];
}
}
fout << sum;
}
fin.close();
fout.close();
}