poj-3254 Corn fields (pressure DP)

Source: Internet
Author: User

Topic Links:

Corn fields

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 12175 Accepted: 6398

Description

Farmer John had purchased a lush new rectangular pasture composed of M by N (1≤ M ≤ 12; 1≤ n ≤12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares is infertile and can ' t be planted. Canny FJ knows that the cows dislike eating close to all other, so when choosing which squares to plant, he avoids choosi Ng squares that is adjacent; No. Chosen squares share an edge. He has not yet made the final choice as to which squares to plant.

Being a very open-minded man, Farmer John wants to consider all possible options for what to choose the squares for Plantin G. He's so open-minded that he considers choosing no squares as a valid option! Farmer John determine the number of ways he can choose the squares to plant.

Input

Line 1:two space-separated integers: Mand N
Lines 2.. M+1:line I+1 describes row Iof the pasture with Nspace-separated integers indicating whether a square is fertile (1 for fertile, 0 for infertile)

Output

Line 1:one integer:the number of ways that FJ can choose the squares modulo 100,000,000.

Sample Input

2 31 1 10 1 0

Sample Output

9

Test instructions

To N*m lattice, the adjacent lattice can not all plant, now give 0 of the lattice can not plant, ask you how many kinds of plant methods;

Ideas:

DP[I][J] indicates that the status of line I is J before I line a total number of methods, and then is the legal state to find and transfer, the specific look at the code;

AC Code:
//#include <bits/stdc++.h>#include <vector>#include<iostream>#include<queue>#include<cmath>#include<map>#include<cstring>#include<algorithm>#include<cstdio>using namespacestd;#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong Longll;template<classT>voidRead (t&num) {    CharCH;BOOLf=false;  for(Ch=getchar (); ch<'0'|| Ch>'9'; f= ch=='-', ch=GetChar ());  for(num=0; ch>='0'&&ch<='9'; num=num*Ten+ch-'0', ch=GetChar ()); F&& (num=-num);}intstk[ -], Tp;template<classT> Inlinevoidprint (T p) {if(!p) {Puts ("0");return; }  while(p) stk[++ TP] = p%Ten, p/=Ten;  while(TP) Putchar (stk[tp--] +'0'); Putchar ('\ n');}ConstLL mod=1e8;Const DoublePi=acos (-1.0);ConstLL inf=1e18;Const intN= (1<< A)+Ten;Const intmaxn=1005; LL dp[ -][n];inta[ the][ the],temp[ the],num[ the],cnt,b[n];intn,m;intOkintXinty) {    if(x&y)return 0; return 1;}intCheckintx) {MST (temp,0); ints=0;  while(x) {temp[++s]= (x&1); X>>=1; }     for(intI=1; i<=s;i++)    {        if(temp[i]&&temp[i+1])return 0; }    return 1;}voidInit () {CNT=0;  for(intI=0;i< (1&LT;&LT;M); + +i) {if(check (i)) b[++cnt]=i; }}intMain () {read (n); read (m);  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++) read (a[i][j]);  for(intI=1; i<=n;i++)    {        intx=0, w=1;  for(intj=1; j<=m;j++)        {            if(!a[i][j]) x+=W; W*=2; } Num[i]=x;    } Init ();  for(intI=1; i<=cnt;i++)    {        if(OK (num[1],b[i]) dp[1][i]=1;//Ans+=dp[1][i];    }     for(intI=2; i<=n;i++)    {         for(intj=1; j<=cnt;j++)        {            if(OK (Num[i],b[j])) { for(intk=1; k<=cnt;k++)                if(OK (num[i-1],B[K]) &&OK (B[j],b[k])) Dp[i][j]+=dp[i-1][k],dp[i][j]%=mod;//Ans+=dp[i][j],ans%=mod;}}} LL ans=0;  for(intj=1; j<=cnt;j++)            if(OK (num[n],b[j])) ans+=dp[n][j],ans%=MoD; cout<<ans<<"\ n"; return 0;}



poj-3254 Corn fields (pressure DP)

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.