E - Minesweeper HDU - 5965 (simple for loop)

Title: CNR and Minesweeper Xiaolu is particularly fond of puzzles, her two most recent addicted can not extricate themselves. 
The game's interface is a matrix, the matrix in a lattice some mines, which Sublattices no mines. Game, the grid is known and may be unknown state. If a grid is not known mines, it will be written on the grid there is a single digit, this represents the total number of grid connectivity eight adjacent grid mines. 
The game is now in a CNR and Xiaolu 3 rows and N columns (both from a start number of consecutive positive integers with) a matrix, this matrix, the second row of the grid are all known, and which did not mines; while the other two lines are unknown, and wherein the total number of mines is also unknown. 
CNR and Xiaolu want to know, line 1 and line 3 How many legitimate programs of the laying of mines.

Input test data comprising a plurality of sets, the first line of a positive integer T, denotes the number of data sets. 
Each data row only by the length of digits of N non-empty strings, there is a matrix showing three rows and N columns, a string of alphanumeric characters i represents a number 2 matrix in the i-th row in the grid. 
To ensure that string length N <= 10000, the number of data sets <= 100. 
Output per line only one number, indicates the result placed mines mod100,000,007 number of programs.

Sample Input

2
22
000

Sample Output

6 
1 

idea: start from the first row there are three cases (0,1,2) a mine
one by one enumeration in the past
as long as the first column of the second row can also be identified to determine the next you can determine
I wa a two-point the last one did not determine there is currently a face to put <0 or> 2 mine would break out, at this time has no solution (I> 3 did not pay attention)
Code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 100000007
int main()
{
    int i,j,n,m,t;
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int flag=1;
        int a[10005];
        for(i=0;s[i];i++)
        {
            a[i]=s[i]-'0';
            if(a[0]>4)flag=0;
            if(a[i]>6)flag=0;
        }
        if(flag==0)
        {
            cout<<0<<endl;
            continue;
        }
        int f[10005],x[10005];
        int len=s.size(),last;
        ll sum=0,ans;
        for(J = 0 ; J <= 2 ; J ++ ) 
        { 
            Memset (F, 0 , the sizeof (F)); // To put Reynolds numbers 
            Memset (X, 0 , the sizeof (X)); // take several mine 
            last J =; // first Ray columns 
            for (I = 0 ; I <len; I ++ ) 
            { 
                F [I] = Last; // to put 
                IF (I == 0 ) X [I] = A [I] -f [I]; // also 
                the else X [I] = A [I] -f [I] -f [I- . 1 ]; // also
                last=x[i];
                if(last<0||last>2)break;
            }
            ll ans=0;
            if(i==len&&x[i-1]==0)
            {
                ans=1;
                for(i=0;i<len;i++)if(f[i]==1)ans=ans*2%mod;
            }
            sum=ans%mod+sum%mod;
         }
        cout<<sum%mod<<endl;
    }
}
View Code

 

Guess you like

Origin www.cnblogs.com/ydw--/p/11300053.html