P1879-[USACO06NOV]玉米田Corn Fields

 1 #include <bits/stdc++.h>
 2 #define _for(i,a,b) for(register int i = (a);i < b;i ++)
 3 #define _rep(i,a,b) for(register int i = (a);i > b;i --)
 4 #define INF 0x3f3f3f3f
 5 #define MOD 100000000
 6 #define maxn 1<<13
 7 typedef long long ll;
 8 
 9 using namespace std;
10 typedef pair<int,int> P;
11 inline ll read()
12 {
13     ll ans = 0;
14     char ch = getchar(), last = ' ';
15     while(!isdigit(ch)) last = ch, ch = getchar();
16     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
17     if(last == '-') ans = -ans;
18     return ans;
19 }
20 inline void write(ll x)
21 {
22     if(x < 0) x = -x, putchar('-');
23     if(x >= 10) write(x / 10);
24     putchar(x % 10 + '0');
25 }
26 int M,N;
27 int a[maxn][maxn];
28 int dp[15][maxn];
29 int validState[15][maxn];
30 int validNum[15];
31 void Init(int curValidState,int col,int row)
32 {
33     if(col > N-1)
34     {
35         validState[row][++validNum[row]] = curValidState;
36         return ;
37     }
38     Init(curValidState,col+1,row);
39     if(a[row][col+1])
40         Init(curValidState + (1<<col),col + 2,row);
41 }
42 int main()
43 {
44     M = read();
45     N = read();
46     _for(i,1,M+1)
47     _for(j,1,N+1)
48     a[i][j] = read();
49 
50     _for(i,1,M+1)
51     Init(0,0,i);
52 
53     _for(i,1,validNum[1]+1)
54     dp[1][i] = 1;
55 
56     _for(i,2,M+1)
57     _for(j,1,validNum[i]+1)
58     _for(k,1,validNum[i-1]+1)
59     {
60         if(validState[i][j]&validState[i-1][k]) continue;
61         dp[i][j] += dp[i-1][k];
62         dp[i][j] %= MOD;
63     }
64     ll rnt = 0;
65     _for(i,1,validNum[M]+1)
66     {
67         rnt += dp[M][i];
68         rnt %= MOD;
69     }
70     write(rnt);
71     return 0;
72 }

 

posted @ 2019-10-05 15:12  Asurudo  阅读(131)  评论(0编辑  收藏  举报