Bzoj 1088(模拟)

Bzoj 1088
bzoj上的图被吃掉了。。搞的我题意弄错
这题答案只可能在$[0,2]$,因为不然第一行无法满足条件。
观察发现,因为第二列的数值是第一列的三个值相加,所以先确定了第一行的前两格,后面就可以减一下推了,然后判断一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
using namespace std;
const int MAXN = 10000 + 5;
int n, l1[MAXN], l2[MAXN];
int cl() {
for (int i = 2; i <= n; i++) l1[i + 1] = l2[i] - l1[i] - l1[i - 1];
for (int i = 1; i <= n; i++) if (l1[i] > 1) return 0;
if (l1[n + 1] >= 1) return 0;
return 1;
}
void clean() {}
void solve() {
clean();
int ans = 0;
for (int i = 1; i <= n; i++) scanf("%d", &l2[i]);
for (int i = 0; i <= l2[1]; i++) {
ms(l1, 0), l1[1] = i, l1[2] = l2[1] - i;
ans += cl();
}
printf("%d\n", ans);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);freopen("1.out", "w", stdout);
#endif
scanf("%d", &n), solve();
return 0;
}

------ 本文结束 ------