Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int map[11], N, M;
- int D[11][1024];
- int max(int a, int b) {
- return a>b?a:b;
- }
- int main() {
- int C, i, j, s, k;
- char c;
- scanf("%d", &C);
- for (int t=1; t<=C; t++) {
- scanf("%d %d", &N, &M);
- for (i=1; i<=N; i++) {
- scanf("%*c");
- map[i] = 0;
- for (j=0; j<M; j++) {
- scanf("%c", &c);
- map[i] <<= 1;
- if (c == 'x') map[i] |= 1;
- }
- }
- for (i=1; i<=N; i++) {
- for (s=0; s<(1<<M); s++) {
- if (map[i] & s) {
- D[i][s] = -1;
- continue;
- }
- for (k=0; k<M; k++) {
- int mask = 3<<k;
- if ((s & mask) == mask) {
- D[i][s] = -1;
- break;
- }
- }
- if (k<M) continue;
- int cnt = 0;
- for (k=0; k<M; k++) {
- if (s & (1<<k)) cnt++;
- }
- int see = ((s<<1)|(s>>1))&((1<<M)-1);
- D[i][s] = 0;
- for (int prev=0; prev<(1<<M); prev++) {
- if ((prev & see) || D[i-1][prev] == -1) continue;
- D[i][s] = max(D[i][s], D[i-1][prev]+cnt);
- }
- }
- }
- int res = 0;
- for (s=0; s<(1<<M); s++) {
- res = max(res, D[N][s]);
- }
- printf("%d\n", res);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment