/*8、求網格中的黑點分佈。現有6*7的網格,在某些格子中有黑點,
已知各行與各列中有黑點的點數之和,請在這張網格中畫出黑點的位置。*/
#define ROWS 6
#define COLS 7
int R[ROWS] = {2, 0, 4, 3, 4, 0}; // 各行黑點數和的情況
int C[COLS] = { 4, 1, 2, 2, 1, 2, 1 }; // 各列黑點數和的情況
int rcount[6];
int ccount[7];
int pos[6][7];
//------------------
void output()
{
for(int r=0;r<6;r++)
{
for(int c=0;c<7;c++)
{
cout<<pos[r][c];
}
cout<<endl;
}
}
//------------------
int valid(int i,int j,int x,int y)
{
if( (x>=R[i])||(y>=C[j]) ||(pos[i][j]==1) )
return 0;
return 1;
}
//------------------
void set(int n)
{
if(n==13)
{
output();
}
int i,j;
for(i=0;i<ROWS;i++)
{
for(j=0;j<COLS;j++)
{
if(valid(i,j,rcount[i],ccount[j]))
{
pos[i][j]=1;
rcount[i]++;
ccount[j]++;
}
} }
}
//------------------
void main()
{
set(0);
output();
}