BZOJ 1087: [SCOI2005]互不侵犯King
二次联通门 : BZOJ 1087: [SCOI2005]互不侵犯King
/* BZOJ 1087: [SCOI2005]互不侵犯King 状压dp 将每一行棋子的存在状态压成一个整数 f[i][j][k]为第i行第j个状态放k个棋子的方案数 dfs预处理一下转移即可。。 */ #include <cstdio> #define rg register #define Max 12 typedef long long LL; LL f[Max][(1 << 15) + 2][Max * 3]; int c[(1 << 15) | 1], v[(1 << 15) | 1], N, C; void Dfs (int n, int s, int p) { if (p > N) { v[++ C] = n, C[c] = s; return ; } Dfs (n + (1 << p - 1), s + 1, p + 2); Dfs (n, s, p + 1); } int Main () { rg int i, j, k, l; int K; scanf ("%d%d", &N, &K); for (i = 1, Dfs (0, 0, 1); i <= C; ++ i) f[1][v[i]][c[i]] = 1LL; for (i = 2; i <= N; ++ i) for (j = 1; j <= C; ++ j) for (k = 1; k <= C; ++ k) { if (v[j] & v[k]) continue; if (((v[j] << 1) & v[k]) || ((v[j] >> 1) & v[k])) continue; for (l = K; l >= c[j]; -- l) f[i][v[j]][l] += f[i - 1][v[k]][l - c[j]]; } LL Answer = 0; for (i = 1; i <= C; ++ i) Answer += f[N][v[i]][K]; printf ("%lld", Answer); return 0; } int ZlycerQan = Main (); int main (int argc, char *argv[]) { return 0; }
myj 吊打我Orz,xxy 捆起来打我Orz,myl 文化课上天Orz, lrh 姿势水平敲高Orz, hkd 特别胖Orz%%%,cys 智商感人Orz,syl zz专业Orz,我没有学上, 我们未来一片光明