# 思路

f[i][j][s] += f[i-1][j-cnt[j]][pre] 事实上，这更像一个递推。

# Code

#include <bits/stdc++.h>
using namespace std;
const int maxn = 10;
const int maxs = (1 << 10) + 1;
int n, k, stat[maxs], m = 0;
bool mp[maxs][maxs];
long long f[maxn][maxn * maxn][maxs];
int ct[maxs];
void dfs(int p, int cnt, int x) {
if (p >= n || cnt > k)
return;
stat[m++] = x;
ct[m - 1] = cnt;
for (int i = p + 1; i < n; i++) {
if (abs(p - i) > 1 || p == -1)
dfs(i, cnt + 1, x | (1 << i));
}
}
int main() {
scanf("%d%d", &n, &k);
dfs(0 - 1, 0, 0);
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
mp[i][j] = mp[j][i] = (stat[i] & stat[j]) || (stat[i] >> 1 & stat[j]) ||
(stat[j] >> 1 & stat[i])
? 0
: 1;
}
}
for (int i = 0; i < m; i++) {
f[0][ct[i]][i] = 1LL;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j <= k; j++) {
for (int now = 0; now < m; now++) {
if (ct[now] > j)
continue;
for (int l = 0; l < m; l++) {
if (mp[l][now] && ct[l] + ct[now] <= j) {
f[i][j][now] += f[i - 1][j - ct[now]][l];
}
}
}
}
}
long long ans = 0;
for (int i = 0; i < m; i++) {
ans += f[n - 1][k][i];
}
printf("%lld", ans);
return 0;
}



posted on 2017-01-06 17:35  蒟蒻konjac  阅读(214)  评论(0编辑  收藏

• 随笔 - 168
• 文章 - 0
• 评论 - 33