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

刚看你的回复,再看看自己的代码,发现自己傻了。。。白白写多一重循环。改了

Posted by userfriendly at 2009-02-20 21:06:34 on Problem 1321
In Reply To:我的程序是直接套用了回溯的通用代码,通用性强,但可能灵活性不够导致了效率问题.很郁闷.解数独的时候,也是因为效率不好导致TLE Posted by:gfedcba at 2009-02-20 20:26:41
本行不放的情况=f(r+1, k)。。。 我居然重复去算。。
应该这样写。。 真白痴。。
int dfs(int r, int k)
{
	int ret=0;
	if(r>n-k) return 0;
	if(k==0) return 1;
	ret+=dfs(r+1, k);
	for(int j=0; j<n; j++)
		if(cb[r][j]==1 && rm[r]==0 && cm[j]==0) // can place chess
		{
			rm[r]=1; cm[j]=1;
			ret+=dfs(r+1, k-1);
			rm[r]=0; cm[j]=0;
		}
	return ret;
}

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