BZOJ 3195 [Jxoi2012]奇怪的道路 | 状压DP

BZOJ 3195

题解

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;
typedef long long ll;
template <class T>
char c;
bool op = 0;
while(c = getchar(), c < '0' || c > '9')
if(c == '-') op = 1;
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9')
x = x * 10 + c - '0';
if(op) x = -x;
}
template <class T>
void write(T x){
if(x < 0) putchar('-'), x = -x;
if(x >= 10) write(x / 10);
putchar('0' + x % 10);
}
const int N = 32, MAXK = 9, P = 1000000007;
int n, m, K, dp[N][N][1 << MAXK][MAXK];
int main(){
dp[1][0][0][1] = 1;
for(int i = 1; i <= n; i++)
for(int j = 0; j <= m; j++)
for(int k = 0; k < (1 << (K + 1)); k++){
for(int l = 1; l <= K; l++){
//printf("dp[%d][%d][%d][%d] = %d\n", i, j, k, l, dp[i][j][k][l]);
(dp[i][j][k][l + 1] += dp[i][j][k][l]) %= P;
if(j < m && i - l > 0)
(dp[i][j + 1][k ^ (1 << l) ^ 1][l] += dp[i][j][k][l]) %= P;
}
if(!(k >> K & 1))
(dp[i + 1][j][k << 1][1] += dp[i][j][k][K]) %= P;
}
write(dp[n][m][0][K]), enter;
return 0;
}

posted @ 2018-01-10 16:24  胡小兔  阅读(283)  评论(0编辑  收藏  举报