poj 1321 棋盘问题

题目链接:poj1321

中文题就不多解释题意了。

解题思路:注意平常的可以用点都用.表示, 结果这道题的可用点竟然是用#表示的。简单粗暴的DFS,注意标记量的备份即可轻松AC。

/*********************************************************************
  FileName: 1321.cpp
  Author: wing
  Created Time: 2014年07月30日 星期三 11时49分29秒
*********************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k;
char ss[10][10];
bool vx[10],vy[10];
int ans;
void dfs(int x,int y,int cnt)
{
	//cout<<" x="<<x<<" y="<<y<<" cnt="<<cnt<<endl;
	//cout<<"  ans="<<ans<<endl;
	if(x==n)return;
	int xx,yy;
	xx=x;
	yy=y+1;
	if(yy>=n)
	{
		yy=0;
		xx++;
	}
	bool flag=false;
	if(ss[x][y]=='#'&&!vx[x]&&!vy[y])
	{
		if(cnt==k-1)
		{
			ans++;
			flag=true;
		}
		if(!flag)
		{
			bool vvx=vx[x],vvy=vy[y];
			vx[x]=true;vy[y]=true;
			//cout<<"fuck"<<endl;
			dfs(xx,yy,cnt+1);
			vx[x]=vvx;vy[y]=vvy;
	
		}
	}
	//cout<<"FFF"<<endl;
	dfs(xx,yy,cnt);
}
int main()
{
	while(scanf("%d%d",&n,&k))
	{
		ans=0;
		memset(vx,false,sizeof(vx));
		memset(vy,false,sizeof(vy));
		if(n==-1&&k==-1)
			break;
		for(int i=0;i<n;i++)
		{
			scanf("%s",ss[i]);
		}
		dfs(0,0,0);
		cout<<ans<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值