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; }

 

posted @ 2017-09-15 17:53  ZlycerQan  阅读(155)  评论(0编辑  收藏  举报