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

好像我写了深搜也没专门剪什么有时0ms有时16ms 。。交流交流。 不懂分析

Posted by userfriendly at 2009-02-20 20:08:18 on Problem 1321 and last updated at 2009-02-20 20:15:31
In Reply To:先后进行1次强剪枝和2次优化之后,从原来的300MS变成80MS,请教牛人们0MS的实现方法.可否帮我将下面的代码由80MS改成0MS.感激不尽 Posted by:gfedcba at 2009-02-20 17:51:11
状态定义为:第一个棋子放在至少第r行,剩余k个棋子要放, f(r, k) 为可能的放法数
那么题目就是求 f(0, k) 

f(r, k)= 本行不放的情况 + 本行放1个的情况 乘以 f(r+1, k-1) , 

因为本行(第r行)放1个的话有多种方法,放哪里影响下一次放的位置,所以必须要记录棋盘状态和回溯。(不满足无后效性唉)

本行不放的情况=f(r+1, k)+...+f(r+k-n, k) 

rm cm分别标记行和列是否可放

我的dfs如下
int dfs(int r, int k)
{
	int ret=0;
	if(k==0) return 1;
	for(int i=r; i<n-k+1; i++)
		for(int j=0; j<n; j++)
			if(cb[i][j]==1 && rm[i]==0 && cm[j]==0) // can place chess
			{
				rm[i]=1; cm[j]=1;
				ret+=dfs(r+1, k-1);
				rm[i]=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