1. 程式人生 > >luogu1879 [USACO06NOV]玉米田Corn Fields

luogu1879 [USACO06NOV]玉米田Corn Fields

namespace markdown ans out source ios pac turn main

學習位運算

#include <iostream>
#include <cstdio>
using namespace std;
int n, m, dp[15][4105], a[15], uu, ans;
const int mod=100000000;
int main(){
    cin>>m>>n;
    for(int i=1; i<=m; i++)
        for(int j=1; j<=n; j++){
            scanf("%d", &uu);
            a[i] |= uu << (j-1
); } for(int i=0; i<(1<<n); i++) if((i|a[1])==a[1] && (i&(i<<1))==0) dp[1][i] = 1; for(int i=2; i<=m; i++) for(int j=0; j<(1<<n); j++) if((j|a[i])==a[i] && (j&(j<<1))==0) for(int
k=0; k<(1<<n); k++) if((j&k)==0) dp[i][j] = (dp[i][j] + dp[i-1][k]) % mod; for(int i=0; i<(1<<n); i++) ans = (ans + dp[m][i]) % mod; cout<<ans<<endl; return 0; }

luogu1879 [USACO06NOV]玉米田Corn Fields