bzoj1088[SCOI2005]扫雷Mine

写的真是又臭又长,感觉像是个dp结果只是一个简单的判断,定下来第一个和第二个就能推出来全部

/**************************************************************
    Problem: 1088
    User: BPM136
    Language: C++
    Result: Accepted
    Time:20 ms
    Memory:1428 kb
****************************************************************/
 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<bitset>
#define LL long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
inline LL read()
{
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
    return d*f;
}
#define N 10005
int a[N],sum[N];
int f[N][2];
int n,m,ans=0;
 
bitset<N>b;
void check()
{
    fo(i,1,n+1)cout<<b[i]<<' ';cout<<endl;
    fo(i,1,n+1)cout<<sum[i]<<' ';cout<<endl;
    cout<<endl;
}
bool judge(int x1,int x2)
{
    b.reset();
    memset(sum,0,sizeof(sum));
    b[1]=x1;b[2]=x2;
    sum[1]=b[1];sum[2]=b[1]+b[2];
    if(sum[2]!=a[1])return 0;
    if(sum[2]>a[2])return 0;
    fo(i,2,n)
    {
        if (a[i]==sum[i])b[i+1]=0;
        else
        {
            if(sum[i]<a[i])b[i+1]=1;
            else return 0;
        }
        sum[i+1]=b[i]+b[i+1];
        if(b[i-1]+b[i]+b[i+1]!=a[i])return 0;
    }
//  check();
    if(b[n+1]==1)return 0;
    else return 1;
}
 
void init()
{
    n=read();
    fo(i,1,n)a[i]=read();
}
 
void ini()
{
    scanf("%d",&n);
    fo(i,1,n)scanf("%d",&a[i]);
}
 
int main()
{
    ini();
    fo(i,0,1)
    fo(j,0,1)
    {
        if (judge(i,j))ans++;
    }
    printf("%d",ans);
    return 0;
}


你可能感兴趣的:(dp,模拟)