Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by mr146 ( 15 years ago )
#include <iostream>

using namespace std;


char s[100][100];
char x[100][100];


int main()
{
 freopen("input.txt", "r", stdin);
 freopen("output.txt", "w", stdout);
 int _;
 scanf("%d", &_);
 while(_--)
 {
  memset(x, 0, sizeof x);
  memset(s, 0, sizeof s);
  int n, m;
  int res = 1e9;
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= n; i++)
  {   
   scanf("%s", s[i] + 1);
   for(int j = 1; j <= m; j++)
   {
    if(s[i][j] == 'X')
    {
     s[i][j] = 0;
    }
    else
    {
     s[i][j] = 1;
    }
   }
  }
  for(int mask = 0; mask < (1 << m); mask++)
  {
   int cur = 0;
   for(int i = 0; i < m; i++)
   {
    x[1][i + 1] = 0;
    if( (1 << i) & mask)
    {
     x[1][i + 1] = 1;
    }    
   }
   for(int i = 1; i <= n; i++)
   {
    for(int j = 1; j <= m; j++)
    {
     cur += x[i][j];
     x[i + 1][j] = (x[i][j] ^ x[i - 1][j] ^ x[i][j - 1] ^ x[i][j + 1] ^ s[i][j]);
    }
   }
   int<= m; j++)
   {
    ones += x[n + 1][j];
   }
   if(ones) continue;
   res = min(res, cur);
  }
  if(res > 1e8)
  {
   res = -1;
  }
  printf("%d\n", res);
 }
 return 0;
}

 

Revise this Paste

Your Name: Code Language: