luogu P2327 [SCOI2005]扫雷

很好的一道题,仔细思索(在y^3 dalao的帮助下)可以发现答案只有0 1 2三种情况
直接枚举第一位有没有雷,就可以递推了qwq

附上y^3大佬的blogs https://blog.csdn.net/Y_Y_Y_3

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
template<class T>void read(T &x){
	int f=0;x=0;char ch=getchar();
	while(ch<'0'||ch>'9')  {f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
} 

const int N=10007;
int a[N],ans[N];
int yyy,n;
bool b[N];

inline bool yhh(bool qwq){
	memset(b,0,sizeof(b));
	b[1]=qwq;
	for(int i=1;i<=n;++i)
		if(b[i-1]+b[i]+1==a[i]) 
			b[i+1]=1;
	if(b[n+1]) return 0;
	for(int i=1;i<=n;++i)
		if(b[i-1]+b[i]+b[i+1]!=a[i])
			return 0;
	
	return 1;
}

int main(){
	read(n);
	for(int i=1;i<=n;++i)
		read(a[i]);
	if((n==1&&a[1]>1)||(n==2&&a[1]+a[2]>=5)){
		printf("0
");
		return 0;
	}
	printf("%d
",yhh(1)+yhh(0));
	return 0;
}
原文地址:https://www.cnblogs.com/Peper/p/9965422.html