1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| #include<stdio.h> #include<string.h> #define mmset(a,b) memset(a,b,sizeof(a)) const int INF = 1 << 12 + 5; int dp[15][INF]; int data[15][15]; int n,m;
void dfs(int i,int j,int state,int next,int flag); int main() { while(~scanf("%d%d",&n,&m)) { for(int i = 1; i <= n; i++) { for(int j = 0; j < m; j++) { scanf("%d",&data[i][j]); } } mmset(dp,0); dp[0][0] = 1;
for(int i = 0; i < n; i++) { for(int state = 0; state < (1<<m); state++) { if(dp[i][state] > 0) { dfs(i,0,state,0,0); } } } int ans = 0;
for(int state = 0; state < (1<<m); state++) { if(dp[n][state] > 0) { ans=(ans+dp[n][state])%100000000; } } printf("%d\n",ans); } return 0; } void dfs(int i,int j,int state,int next,int flag) { if(j == m) { dp[i+1][next] = (dp[i+1][next] + dp[i][state])%100000000; }
else { if(data[i+1][j] == 1 && (state & (1<<j)) == 0 && flag== 0) { if(flag == 0||flag == 1) { dfs(i,j+1,state,next,0); } if(flag == 0) { dfs(i,j+1,state,next | (1<<j),1); } } else { dfs(i,j+1,state,next,0); } } }
|