P2327 [SCOI2005]扫雷
题目描述
输入输出格式
输入格式:第一行为N,第二行有N个数,依次为第二列的格子中的数。(1<= N <= 10000)
输出格式:一个数,即第一列中雷的摆放方案数。
输入输出样例
输入样例#1:
2 1 1
输出样例#1:
2
其实还是扫雷玩的少。。知道思路之后很快
只需枚举前两个各自的情况,后面的各自便能够计算出来
注意几个细节(在代码里面)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define lowbit(a) ((a) & (-(a)))
int read()
{
int x = 0;char ch = getchar();char c = ch;
while(ch > '9' || ch < '0')c = ch, ch = getchar();
while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
if(c == '-')return -x;
return x;
}
const int INF = 0x3f3f3f3f;
const int MAXN = 10000 + 10;
int n;
int num[MAXN];
int cnt;
void work(int a,int b)
{
if(a + b != num[1] || a + b > num[2])return;
for(int i = 2;i < n;i ++)
{
int c = num[i] - a - b;
if(c < 0 || c > 1)return;//别忘了c>1
a = b;
b = c;
}
if(num[n] != a + b)return;//别忘了特判最后一个
cnt ++;
}
int main()
{
n = read();
for(int i = 1;i <= n;i ++)
{
num[i] = read();
}
work(0,0);
work(0,1);
work(1,0);
work(1,1);
printf("%d", cnt);
return 0;
}