func_code_string: #include <bits/stdc++.h>   using namespace std;   char mtx[555][555];   long long comb[555][555];   int n, m, MOD;   map<pair<int, int>, long long> dp[555];   long long solve(int col, int empty, int halfempt) {     if (empty < 0 || halfempt < 0) return 0;     if (col == n) {       return empty == 0 && halfempt == 0;     }     if (dp[col].find(make_pair(empty, halfempt)) == dp[col].end()) {       long long ans = 0;       int cnt = 0;       for (int(i) = 0; (i) < (m); (i)++)         if (mtx[i][col] ==  1 ) cnt++;       if (cnt == 0) {         if (halfempt == 0) {           ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2);         } else {           ans += comb[halfempt][2] * solve(col + 1, empty, halfempt - 2);           if (empty != 0) {             ans += comb[halfempt][1] * comb[empty][1] *                    solve(col + 1, empty - 1, halfempt);             ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2);           }         }       } else if (cnt == 1) {         ans = comb[empty][1] * solve(col + 1, empty - 1, halfempt + 1);         ans += comb[halfempt][1] * solve(col + 1, empty, halfempt - 1);       } else         ans = solve(col + 1, empty, halfempt);       ans %= MOD;       dp[col][make_pair(empty, halfempt)] = ans;     }     return dp[col][make_pair(empty, halfempt)];   }   int main() {     scanf( %d%d%d , &n, &m, &MOD);     for (int i = 1; i < 505; i++) {       comb[i][0] = comb[i][i] = 1;       for (int j = 0; j < i; j++) {         comb[i + 1][j + 1] = (comb[i][j] + comb[i][j + 1]) % MOD;       }     }     if (n == m) {       printf( 1 n );       return 0;     }     for (int(i) = 0; (i) < (m); (i)++) scanf( %s , mtx[i]);     long long ans = solve(0, n - m, 0);     printf( %I64d n , ans);     return 0;   }   