-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoj 1002.cpp
96 lines (91 loc) · 2.34 KB
/
zoj 1002.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
using namespace std;
int config(int a[],int row)
{
int r=0;
for(int i=0;i<row;i++)
for(int j=0;j<row;j++)
if(a[i*row+j]==2)
r++;
for(int i=0;i<row;i++)
{
int flag=1;
for(int j=0;j<row;j++)
{
flag*=*(a+i*row+j);
if(flag==0)
flag=1;
else if(flag>3)
return 0;
}
}
for(int i=0;i<row;i++)
{
int flag=1;
for(int j=0;j<row;j++)
{
flag*=*(a+j*row+i);
if(flag==0)
flag=1;
else if(flag>3)
return 0;
}
}
return r;
}
int randall(int a[],int p,int row)
{
int c,c1;
if(p==row*row-1)
{
c=config(a,row);
a[p/row*row+p%row]*=2;
c1=config(a,row);
a[p/row*row+p%row]/=2;
return c1>c?c1:c;
}
c=randall(a,p+1,row);
a[p/row*row+p%row]*=2;
if(config(a,row))
{
c1=randall(a,p+1,row);
if(c1>c)
{
a[p/row*row+p%row]/=2;
return c1;
}
else
{
a[p/row*row+p%row]/=2;
return c;
}
}
else
{
a[p/row*row+p%row]/=2;
return c;
}
}
int main()
{
int row;
while(1)
{
int board[15]={0};
cin>>row;
if(row==0)
break;
for(int i=0;i<row;i++)
for(int j=0;j<row;j++)
{
char bh;
cin>>bh;
if(bh=='.')
board[i*row+j]=1;
}
int max;
max=randall(board,0,row);
cout<<max<<endl;
}
return 0;
}