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

Re:我的是这样

Posted by celia01 at 2012-01-31 15:32:21 on Problem 2960 and last updated at 2012-01-31 15:32:54
In Reply To:同慢,求快速计算mex的方法~~ Posted by:tongjiantao at 2011-03-31 16:28:07
> 求快速计算mex的方法~~
计算sg值时用记忆化搜索,我的是这样写的:
ps: vis只用开100+就行了,我之前就因为这费了好多时间,因为每次调用dfs都要新申请数组
int dfs(int x){
	if(sg[x]!=-1) return sg[x];
	int i, f=0;
	bool vis[105] = {0};
	for(i=0;i<k;i++){
		if(x-s[i]>=0){
			dfs(x-s[i]);
			vis[sg[x-s[i]]] = true;
		}
	}
	for(i=0;i<105;i++){
		if(vis[i]==false){
			f = i;
			break;
		}
	}
	return sg[x] = f;
}

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