Guest User

Untitled

a guest
Dec 10th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int map[11], N, M;
  4. int D[11][1024];
  5.  
  6. int max(int a, int b) {
  7. return a>b?a:b;
  8. }
  9.  
  10. int main() {
  11. int C, i, j, s, k;
  12. char c;
  13. scanf("%d", &C);
  14. for (int t=1; t<=C; t++) {
  15. scanf("%d %d", &N, &M);
  16.  
  17. for (i=1; i<=N; i++) {
  18. scanf("%*c");
  19. map[i] = 0;
  20. for (j=0; j<M; j++) {
  21. scanf("%c", &c);
  22. map[i] <<= 1;
  23. if (c == 'x') map[i] |= 1;
  24. }
  25. }
  26.  
  27. for (i=1; i<=N; i++) {
  28. for (s=0; s<(1<<M); s++) {
  29. if (map[i] & s) {
  30. D[i][s] = -1;
  31. continue;
  32. }
  33. for (k=0; k<M; k++) {
  34. int mask = 3<<k;
  35. if ((s & mask) == mask) {
  36. D[i][s] = -1;
  37. break;
  38. }
  39. }
  40. if (k<M) continue;
  41.  
  42. int cnt = 0;
  43. for (k=0; k<M; k++) {
  44. if (s & (1<<k)) cnt++;
  45. }
  46.  
  47. int see = ((s<<1)|(s>>1))&((1<<M)-1);
  48. D[i][s] = 0;
  49. for (int prev=0; prev<(1<<M); prev++) {
  50. if ((prev & see) || D[i-1][prev] == -1) continue;
  51. D[i][s] = max(D[i][s], D[i-1][prev]+cnt);
  52. }
  53. }
  54. }
  55.  
  56. int res = 0;
  57. for (s=0; s<(1<<M); s++) {
  58. res = max(res, D[N][s]);
  59. }
  60.  
  61. printf("%d\n", res);
  62. }
  63.  
  64. return 0;
  65. }
Add Comment
Please, Sign In to add comment