BZOJ 1088 水模拟

BZOJ水一道~

枚举前两个位置是否放雷,模拟向下推。能够则ans++


#include "stdio.h"
#include "string.h"

int a[10010],b[10010],n;

int judge()
{
    int i;
    for (i=3;i<=n;i++)
    {
        b[i]=a[i-1]-b[i-1]-b[i-2];
        if (b[i]<0) return 0;
        if (b[i]>1) return 0;
    }
    if (b[n-1]+b[n]!=a[n]) return 0;
    return 1;
}
int main()
{
    int i,ans;
    while (scanf("%d",&n)!=EOF)
    {
        for (i=1;i<=n;i++)
            scanf("%d",&a[i]);

        if (a[1]>2) {printf("0\n");continue;}
        ans=0;

        for (i=0;i<=a[1];i++)
        {
            b[1]=i; b[2]=a[1]-b[1];

            if (b[2]<=1 && judge()==1)
                ans++;
        }
        printf("%d\n",ans);

    }
    return 0;
}


posted @ 2017-06-08 21:28  yfceshi  阅读(150)  评论(0编辑  收藏  举报