UESTC_ Winter Horse Party cdoj 882

Source: Internet
Author: User

Winter Horse PartyTime limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus

Finally to the Winter horse party and the Snow Cabbage Party showdown, for convenience, their battle of the land can be seen as an nxm matrix.

On the eve of the battle, the Winter Horse party in the Snow cabbage party in the inside told Bai Co home Kuros , the Snow cabbage party has been in their battle to bury the land mines.

Kurosbased on years of experience in mine clearance, the white-house speculated that the snow-cabbage party would not put landmines in adjacent squares. (two squares are adjacent to each other) and, according to the advance force, some of the lattice's land is very hard and it is impossible to bury mine.

In order to win the final victory of the Winter Horse party, Kuros I wonder how many kinds of programs The snow cabbage party has to put on landmines.

Input

Enter first behavior two integersn,m , which indicates the size of the ground to be decisive. (1≤n< Span id= "mathjax-span-773" class= "Mo" >≤12 ,1 ≤m≤ 12)

Next n rows < Span id= "mathjax-span-785" class= "math" > m Number, 0 indicates that the land cannot be mined, 1 indicates that the land can be planted with landmines.

Output

A row, an integer that represents the total number of scenarios, and the remainder of the answer taken 100000000 .

Sample Input and output
Sample Input Sample Output
2 31 1 10 1 0
9
Source2014 UESTC Training for Dynamic programmingProblem Solving Reportf (i,j) indicates the number of scenarios where line I is placed in J.use a Dfs to transfer. Note the situation:1. The position of the previous line has been put on a mine, then this line of this must not be put2. The title expressly prohibits the placement of mines in this line of work.because my DFS does not check the same line of two mines (illegal), so when the transfer of J must be legal, the final answer count when J must also be legal.The most important thing is ... Don't explode a long long (I hung two rounds.) )the code is optimized with a scrolling array ~
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5typedefLong Longll;6 using namespacestd;7 Constll mod =100000000;8ll f[2][1<< -];9 BOOLg[ the][ the];Ten intN,m,r,cur=0; One  A voidDfsintPosintval,ll Add) - { -   if(pos = =-1) theF[cur][val] = (F[cur][val] + add)%MoD; -   Else -    { -          if(Val >> Pos &1|| !g[r][pos])//This position on the previous line has been put on mine/This place is not allowed to put mines +DFS (pos-1, Val & ~ (1<<POS), add); -          Else +           { ADFS (pos-1, Val | (1<<POS), add); atDFS (pos-1, Val,add); -        } -    }  - } -  -  in BOOLCheckintx) - { to    intPre =0; +     for(inti =0; I < m; ++i) -     { the         intNEWX = x >> I &1; *         if(Newx &&pre) $          return false;Panax NotoginsengPre =newx; -     } the    return true; + } A  the intMainintargcChar*argv[]) + { -Memset (G,true,sizeof(g)); $Memset (F,0,sizeof(f)); $scanf"%d%d",&n,&m); -    for(inti =0; I < n; ++i) -     for(intj =0; J < M; ++j) the     { -         inttemp;Wuyiscanf"%d",&temp); the         if(!temp) -G[I][J] =false; Wu     } -R =0; AboutDFS (M-1,0,1); $    for(inti =1; I < n; ++i) -     { -Cur ^=1; -R =i; A         for(intj =0; J < (1<< m); + + j) F[cur][j] =0; +         for(intj =0; J < (1<< m); ++j) the         if(Check (j)) -DFS (M-1, j,f[cur^1][j]); $       } the   intAns =0; the    for(inti =0; I < (1<< m); ++i) the    if(check (i)) theAns = (ans + f[cur][i])%MoD; -printf"%lld\n", ans%MoD); in   return 0; the}

UESTC_ Winter Horse Party cdoj 882

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.