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了我一个多小时我没找到错误,跟Java一样这么矫情?

Posted by qq1250173534 at 2020-03-01 17:51:28 on Problem 1321
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
char m[10][10];
int cnt,n,k;
int q[10];
void dfs(int row,int num)
{
	if(num >= k){
		cnt++;
		return ;
	}
	int i,j;
	for(i = row;i < n;i++){	//我下面传row,这里row+1有什么问题嘛?	
		for(j = 0;j < n;j++){		
			if(q[j] == 0 && m[i][j] != '.'){
				q[j] = 1;
				dfs(i+1,num+1);
				q[j] = 0;
			}
		}
	}
}
int main()
{
	while(~scanf("%d%d",&n,&k)){
		if(n == -1 && k == -1){
			break;
		}
		for(int i = 0;i < n;i++){
			scanf("%s",m[i]);
		}
		memset(q,0,sizeof(q));
		cnt = 0;
		dfs(0,0);
		printf("%d\n",cnt);
	}
	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