_bzoj1088 [SCOI2005]扫雷Minedp
Posted ciao_sora
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了_bzoj1088 [SCOI2005]扫雷Minedp相关的知识,希望对你有一定的参考价值。
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1088
简单的状压dp(话说本题的编号减1,即1087,也是一道状压dp),不解释。
#include <cstdio> const int maxn = 10005; int n, b[maxn]; long long f[maxn][8]; int main(void) { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", b + i); if (b[i] > 3 || b[i] < 0) { puts("0"); return 0; } } if (b[1] == 3 || b[n] == 3) { puts("0"); return 0; } if (b[1] == 0) { f[1][0] = 1; } else if (b[1] == 1) { f[1][0] = f[1][1] = 1; } else { f[1][1] = 1; } for (int i = 2; i <= n; ++i) { if (b[i - 1] == 0) { f[i][0] = f[i - 1][0] + f[i - 1][4]; } else if (b[i - 1] == 1) { f[i][1] = f[i - 1][0] + f[i - 1][4]; f[i][2] = f[i - 1][1] + f[i - 1][5]; f[i][4] = f[i - 1][2] + f[i - 1][6]; } else if (b[i - 1] == 2) { f[i][3] = f[i - 1][1] + f[i - 1][5]; f[i][5] = f[i - 1][2] + f[i - 1][6]; f[i][6] = f[i - 1][3] + f[i - 1][7]; } else { f[i][7] = f[i - 1][3] + f[i - 1][7]; } } if (b[n] == 0) { printf("%lld\n", f[n][0] + f[n][4]); } else if (b[n] == 1) { printf("%lld\n", f[n][1] + f[n][5] + f[n][2] + f[n][6]); } else if (b[n] == 2) { printf("%lld\n", f[n][3] + f[n][7]); } return 0; }
以上是关于_bzoj1088 [SCOI2005]扫雷Minedp的主要内容,如果未能解决你的问题,请参考以下文章