poj 1753 Flip Game
题意和2965差不多,思路也是一样的:链接:2965
代码:
View Code
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int s[16] =
{
0xc800,0xe400,0x7200,0x3100,
0x8c80,0x4e40,0x2720,0x1310,
0x08c8,0x04c4,0x0272,0x0131,
0x008c,0x004e,0x0027,0x0013
};
int result = 17;
int tt = 0;
int num = 0;
void search(int d,int step)
{
if(step >= 17 )
return ;
if(d >= 16)
{
if((num == tt || num == 0)&&step < result)
result = step;
return ;
}
num = num^s[d];
search(d+1,step+1);
num = num^s[d];
search(d+1,step);
}
int main()
{
char a;
for(int i = 1; i <= 16 ;++i)
{
a=getchar();
if('\n' == a)
i--;
else
{
num = num <<1;
if('b' == a)
num++;
}
}
for(int i = 1; i <= 16; ++i)
tt = (tt<<1)^1;
search(0,0);
if(result > 16)
printf("Impossible\n");
else
printf("%d\n",result);
return 0;
}