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 |
想问一个问题:我是用DFS实现的匈牙利算法,代码跟大多数人的写法一样: int DFS_hungary(int cur) { for (int i=1;i<=m;++i) { if (will[cur][i] && !used[i]) { used[i] = true; if (py[i]==-1 || DFS_hungary(py[i])) { py[i] = cur; px[cur] = i; return 1; } used[i] = false; //如果加这一句就TLE了,请问为什么? } } return 0; } TLE了很多次,终于发现我多写了加注释的那句话。可是我还是想不明白, 为什么加这一句会有问题?回溯时删除访问标记为什么有错?难道会导致无限递归?即使有无限递归不是应该爆栈吗,怎么是TLE? Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator