| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:我的是这样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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator