Bzoj 1088: [SCOI2005] Minesweeper Mine
Write a pitch, not a DP of the game problem
If you know the former \ (i-1\) item, the first \ ( i\) item will be known by the second column of section \ (i-1\) .
Set \ (f[i]\) is the first column of the i\ line position If there is thunder, Ray,\ (f[i] = 1\), no Thunder \ (F[i] = 0\)
\ (a[i]\) is what the topic reads.
Then the transfer equation is \ (f[i] = a[i-1]-f[i-1]-f[i-2]\)
When the limit is not met \ (F[i] < 0\) or $ f[i] > 1$
The first position is discussed. Make the above recursion.
#include <iostream>#include <cstdio>const int maxN = 10000 + 7; int f[maxN],ans,a[maxN]; inline int read() { int x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9') {if(c == '-')f = -1;c = getchar();} while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = getchar();} return x * f;} int n;void work() { for(int i = 2;i <= n;++ i) { f[i] = a[i - 1] - f[i - 1] - f[i - 2]; if(f[i] < 0 || f[i] > 1) return ; } if(a[n] != f[n] + f[n - 1])return ; ans ++; return ;} int main() { n = read(); for(int i = 1;i <= n;++ i) a[i] = read(); for(int i = 0;i < 2;++ i) f[1] = i,work(); printf("%d\n", ans); return 0;}
Bzoj 1088: [SCOI2005] Minesweeper Mine (DP)