算法简记

自己的算法模版笔记

DFS

int dfs(int n,int ans)
{
if(check(n))
return ans;
else
{
for(...)
{
if(use[i]==0)
{
use[i]=1;
dfs(n+1,ans+...);
use[i]=0;
}
}
}
return ans;
}

BFS

void bfs(int s)
{
queue q;
q.push(now);
while(!q.empty())
{
int top=q.front();
q.pop();
for(...)
{
if(right(i))
q.push(i);
}
}
cout<<ans<<endl;
}
Author: Odeinjul
Link: http://odeinjul.ooo/coding-methods.html
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.