题意:
思路:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
const int MAXN=10+5;
int n,m,Q,ans;
int mat[MAXN][MAXN];
void dfs(int x, int y, int cnt)
{
if(x>=n)
{
ans=max(ans,cnt);
return;
}
if(y>=m)
{
dfs(x+1,0,cnt);
return;
}
if(mat[x][y])
{
dfs(x,y+1,cnt);
return;
}
dfs(x,y+1,cnt);
int t;
bool flag=false;
for(t=x-1;t>=0;t--)
if(mat[t][y])
break;
for(int i=t-1;i>=0;i--)
{
if(mat[i][y])
{
if(mat[i][y]== 2)
{
flag=true;
}
break;
}
}
if(flag)
{
return;
}
for(t=y-1;t>=0;t--)
{
if(mat[x][t])
break;
}
for(int j=t-1;j>=0;j--)
{
if(mat[x][j])
{
if(mat[x][j]== 2)
{
flag=true;
}
break;
}
}
if(flag)
{
return;
}
mat[x][y]=2;
dfs(x,y+1,cnt+1);
mat[x][y]=0;
}
int main()
{
while(scanf("%d %d %d",&n,&m,&Q)!=EOF)
{
memset(mat,0,sizeof(mat));
for(int i=0;i<Q;i++)
{
int x,y;
scanf("%d %d",&x,&y);
mat[x][y]=1;
}
ans=0;
dfs(0,0,0);
printf("%d\n",ans);
}
return 0;
}