码迷,mamicode.com
首页 > 其他好文 > 详细

_bzoj1088 [SCOI2005]扫雷Mine【dp】

时间:2017-02-06 21:08:00      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:blog   ++i   min   include   amp   lld   状压dp   clu   ++   

传送门: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]扫雷Mine【dp】

标签:blog   ++i   min   include   amp   lld   状压dp   clu   ++   

原文地址:http://www.cnblogs.com/ciao-sora/p/6371587.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!