This blog post for the migration, written on November 4, 2014, does not represent my current views and views. Original address: http://blog.sina.com.cn/s/blog_6022c4720102vrft.html
1088: [SCOI2005] Minesweeper mine Time limit:10 Sec Memory limit:162 MB
submit:1730 solved:1028
[Submit] [Status] Description
I believe everyone has played the game of minesweeper. There are some thunder in a n*m matrix, you need to find out the ray based on some information. Halloween arrived, "Yu" People have a simple game of minesweeper, the rules of the game and the same as mine, if a lattice does not have thunder, then it is the number of the inside of the grid and its 8 connected to the number of thunder. Now the chessboard is NX2, and the first column contains some grids that are thunder, and the second column has no thunder, such as: Because the first column of thunder may have many options to meet the number of the second column limit, your task is to determine the second column according to the information of the first quagliere how many kinds of placement scheme.
Input
The first behavior n, the second row has n number, in order the number of the second column in the lattice. (1<= N <= 10000)
Output
A number, that is, the number of thunder in the first column.
Sample Input2
1 1Sample Output2 Analysis: By the second column gives you the hint, obtains the first row thunder the possibility. The students who have played mine clearance may be aware that this problem can only be reached in the first two, and there is only one possibility behind the Thunder. the dp[can be dynamically programmed], because there is no aftereffect. Code: #include <cstdio>#include <cstring> #define MAX 10001 int N,ans=0,f[max],a[max]; int check (){for (int i=2;i<n;i++) {F[i+1]=a[i]-f[i]-f[i-1];if (f[i+1]<0) return 0; }if (a[n]-f[n]-f[n-1]!=0) return 0;return 1;} int main (){scanf ("%d", &n);for (int i=1;i<=n;i++)scanf ("%d", &a[i]);if (a[1]==0) Ans+=check ();else if (a[1]==1) {f[1]=1;Ans+=check ();memset (f,0,sizeof (f));f[2]=1;Ans+=check (); }Else {f[1]=1;f[2]=1;Ans+=check (); }printf ("%d\n", ans);return 0;}
[Puzzle] Minesweeper Mine