Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么tle呀,大牛们,帮我看看

Posted by Headacher at 2008-08-16 16:36:26 on Problem 1321
#include<iostream>
using namespace std;
int n,cnt;
char map[8][8];
bool row[8],col[8];
void solve(int m,int k)
{	int i;
	for(i=0;i<n;i++)
	{	if(map[m][i]=='#'&&!row[m]&&!col[i])
		{	row[m]=1;
			col[i]=1;
			k--;
			if(m+1<n&&k>0) solve(m+1,k);
			if(k==0) cnt++;
			k++;
			row[m]=0;
			col[i]=0;
			if(m+1<n)
			{	
				solve(m+1,k);
			}
		
			
		}
	}
	
}
int main()
{	int i,j,k;
	while((cin>>n>>k)&&n!=-1)
	{	cnt=0;
		memset(row,0,sizeof(row));
		memset(col,0,sizeof(col));
		for(i=0;i<n;i++)
			for(j=0;j<n;j++)
				cin>>map[i][j];
		solve(0,k);
		cout<<cnt<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator