Home/ Article Practice/ 蒙德里安的梦想

蒙德里安的梦想

2025-01-20 23:34  views:201  source:mmyyyy    

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 12, M = 1 << N;
int n, m;
LL f[N][M];
vector<int> state[M];
bool st[M];
int main(){
while (cin >> n >> m, n || m) {
for (int i = 0; i < 1 << n; i ++) {
int cnt = 0;
bool is_valid = true;
for (int j = 0; j < n; j ++)
if (i >> j & 1){
if (cnt & 1){
is_valid = false;
break;
}
cnt = 0;
}
else cnt ++;
if (cnt & 1) is_valid = false;
st[i] = is_valid;
}
for (int i = 0; i < 1 << n; i ++){
state[i].clear();
for (int j = 0; j < 1 << n; j ++)
if ((i & j) == 0 && st[i | j])
state[i].push_back(j);
}
memset(f, 0, sizeof f);
f[0][0] = 1;
for (int i = 1; i <= m; i ++)
for (int j = 0; j < 1 << n; j ++)
for (auto k : state[j])
f[i][j] += f[i - 1][k];
cout << f[m][0] << endl;
}
return 0;
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)