bzoj1088 [SCOI2005]扫雷Mine

题目链接

暴力搜吧。

但是只需要枚举第一列的第一个数为0或1,剩下的数都能够根据第一个数来推出来!!!

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<string>
 5 #include<cstring>
 6 #include<cmath>
 7 #include<algorithm>
 8 #include<ctime>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<set>
13 using namespace std;
14 int n,ans,a[10010],hh[10010];
15 inline int getint()
16 {
17     int f=1,ret=0;
18     char ch=getchar();
19     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
20     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
21     return f==-1?-ret:ret;
22 }
23 int pd()
24 {
25     for(int i=2;i<=n;i++)
26     {
27         hh[i+1]=a[i]-hh[i]-hh[i-1];
28         if(hh[i+1]<0)return 0;
29     }
30     if(a[n]-hh[n-1]-hh[n]==0)return 1;
31     return 0;
32 }
33 int main()
34 {
35     n=getint();
36     for(int i=1;i<=n;i++)a[i]=getint();
37     if(!a[1])ans+=pd();
38     else if(a[1]==1)
39     {
40         hh[1]=1,ans+=pd();
41         memset(hh,0,sizeof(hh));
42         hh[2]=1,ans+=pd();
43     }
44     else hh[1]=hh[2]=1,ans+=pd();
45     printf("%d",ans);
46     return 0;
47 }
原文地址:https://www.cnblogs.com/HugeGun/p/5151527.html