"bzoj1725" [Arrangement of USACO2006 Nov]corn Fields Ranch

Source: Internet
Author: User

Title Description

Farmer John bought a new rectangular ranch, which was divided into M-row N rows (1<=m<=12; 1<=n<=12), each of which was a square piece of land. FJ intends to plant a few plots of land in the pasture for his cows to enjoy. Unfortunately, some of the land is quite barren and cannot be used for grazing. And, the cows like the feeling of a piece of grass, so FJ will not choose two blocks of adjacent land, that is, no two grasslands have a common side. Of course, FJ has not decided on which land to plant grass. As a curious farmer, FJ wondered how many planting options were available to him without regard to the total number of blocks in the meadow. Of course, it is also a scheme to waste new pastures and not to plant grass on any land. Please help FJ calculate the total plan number.

Input

* Line 1th: Two positive integers m and n, separated by a space

* 2nd. M+1 rows: Each row contains n spaces separated by integers, describing the state of each piece of land. The input line i+1 describes the land on line I. All integers are 0 or 1, which is 1, which means the land is fertile enough and 0 means the ground is not suitable for planting grass.

Output

* Line 1th: Outputs an integer that is the remainder of the farm allocation total scheme divided by 100,000,000

Sample Example Input

2 3
1 1 1
0 1 0

Sample output

9

Solving

Bare state compression DP, no optimizations required

F[I][J] Indicates the number of scenarios when the line I state is J.

1#include <cstdio>2#include <algorithm>3 #defineMOD 1000000004 using namespacestd;5 intf[ -][4100], no[ -];6 intMain ()7 {8     intM, N, I, J, K, t, ans =0;9scanf"%d%d", &m, &n);Ten      for(i =1; I <= m; i + + ) One          for(j =1; J <= N; J + + ) A             if(SCANF ("%d", &t) &&!t) -No[i] |=1<< (J-1); -no[0] = (1<< N)-1; thef[0][0] =1; -      for(i =1; I <= m; i + + ) -          for(j =0; J <1<< N; J + + ) -             if(! (No[i] & j) &&! (J & (J <<1))) +                  for(k =0; K <1<< N; K + + ) -                     if(! (No[i-1] & k) &&! (K & (K <<1)) &&! (J &k)) +F[I][J] = (F[i][j] + f[i-1][K])%MOD; A      for(i =0; I <1<< N; i + + ) atAns = (ans + f[m][i])%MOD; -printf"%d\n", ans); -     return 0; -}

"bzoj1725" [Arrangement of USACO2006 Nov]corn Fields Ranch

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.