# BZOJ3195: [Jxoi2012]奇怪的道路【状压DP】

【输入样例1】
3 4 1
【输入样例2】
4 3 3

【输出样例1】
3

【输出样例2】
4
【数据规模】

### HINT

100%的数据满足1 <= n <= 30, 0 <= m <= 30, 1 <= K <= 8.

【题目说明】

## 思路

142857说可以优化掉一个n，但是我懒了

//Author: dream_maker
#include<bits/stdc++.h>
using namespace std;
//----------------------------------------------
typedef pair<int, int> pi;
typedef long long ll;
typedef double db;
#define fi first
#define se second
#define fu(a, b, c) for (int a = b; a <= c; ++a)
#define fd(a, b, c) for (int a = b; a >= c; --a)
#define fv(a, b) for (int a = 0; a < (signed)b.size(); ++a)
const int INF_of_int = 1e9;
const ll INF_of_ll = 1e18;
template <typename T>
bool w = 1;x = 0;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') w = 0, c = getchar();
while (isdigit(c)) {
x = (x<<1) + (x<<3) + c -'0';
c = getchar();
}
if (!w) x = -x;
}
template <typename T>
void Write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) Write(x / 10);
putchar(x % 10 + '0');
}
//----------------------------------------------
const int N = 32;
const int K = 10;
const int Mod = 1e9 + 7;
int dp[N][N][1 << K];
int n, m, k;

void add(int &a, int b) {
if ((a += b) >= Mod) a -= Mod;
}

int main() {
#ifdef dream_maker
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
dp[1][0][0] = 1;
int up = (1 << (k + 2)) - 1;
fu(i, 2, n) {
fu(j, 0, m)
fu(l, 0, up) if ((l & 1) == 0 && dp[i - 1][j][l])
add(dp[i][j][l >> 1], dp[i - 1][j][l]);
fu(j, 1, min(k, i - 1))
fd(l, m, 0)
fu(p, 0, up)
fu(e, 1, l) if (dp[i][l - e][p])
add(dp[i][l][p ^ ((e & 1) << (k + 1)) ^ ((e & 1) << (k - j + 1))], dp[i][l - e][p]);
}
Write(dp[n][m][0]);
return 0;
}

posted @ 2018-11-05 11:32  Dream_maker_yk  阅读(178)  评论(0编辑  收藏  举报