We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int main()
{
int runs;
scanf("%d",&runs);
while (runs--) {
scanf("%d%d",&n,&m);
for (int i = 0;i < n;i++) scanf("%s",g[i]);
int ret = solve();
ret = (ret - 1 + MOD) % MOD;
printf("%d\n",ret);
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Queens on Board
You are viewing a single comment's thread. Return to all comments →
guys this code is work for me.....
include
include
define MOD 1000000007
int n, m; char g[50][5]; int good[50][1 << 5]; int szg[50]; int block[50]; int memo[50][1 << 15]; int memo2[1 << 15];
int spread(int mask) { if (memo2[mask] != -1) return memo2[mask];
int nmask = 0; for (int i = 0; i < m; i++) { if (mask & 1 << 3 * i && i > 0) { nmask |= 1 << 3 * i - 3; } if (mask & 1 << 3 * i + 1) { nmask |= 1 << 3 * i + 1; } if (mask & 1 << 3 * i + 2 && i + 1 < m) { nmask |= 1 << 3 * i + 5; } } return memo2[mask] = nmask; }
int solve (int x, int mask) { if (x == n) return 1;
mask &= ~block[x]; if (memo[x][mask] != -1) return memo[x][mask];
int ret = 0; for (int i = 0; i < szg[x]; i++) {
} return memo[x][mask] = ret; }
int solve() { for (int i = 0; i < n; i++) { block[i] = 0; int cmask = 0; for (int j = 0; j < m; j++) { if (g[i][j] == '#') { cmask |= 1 << j; block[i] |= 7 << 3 * j; } }
} memset(memo,255,sizeof memo); memset(memo2,255,sizeof memo2); return solve(0,0); }
int main() { int runs; scanf("%d",&runs); while (runs--) { scanf("%d%d",&n,&m); for (int i = 0;i < n;i++) scanf("%s",g[i]); int ret = solve(); ret = (ret - 1 + MOD) % MOD; printf("%d\n",ret); } return 0; }