码迷,mamicode.com
首页 >  
搜索关键字:bfs dfs    ( 14889个结果
POJ - 2688 Cleaning Robot
题意:求回收所有垃圾的最短路 思路:先BFS处理两个垃圾的距离,然后DFS记忆化搜索           dp[i][state]表示处理到第i个后状态是state的最短路 #include #include #include #include #include #include using namespace std; const int MAXN = 30; const in...
分类:其他好文   时间:2014-06-19 12:55:30    阅读次数:412
经典图算法Java代码实践:BFS,DFS以及几种最短路径算法
public class City { String name; int id; static int idCounter = 0; public City(String name) { this.name=name; id = idCounter++; } } import java.util.ArrayList; public class Gr...
分类:编程语言   时间:2014-06-19 10:36:26    阅读次数:196
LeetCode:Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 ...
分类:其他好文   时间:2014-06-15 19:55:39    阅读次数:191
NYOJ325 zb的生日 【DFS】
zb的生日 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述今天是阴历七月初五,acm队员zb的生日。zb正在和C小加、never在武汉集训。他想给这两位兄弟买点什么庆祝生日,经过调查,zb发现C小加和never都很喜欢吃西瓜,而且一吃就是一堆的那种,zb立刻下定决心买了一堆西瓜。当他准备把西瓜送给C小加和never的时候,遇到了一个难题,ne...
分类:其他好文   时间:2014-06-15 19:12:07    阅读次数:182
二分匹配模版
const int maxn = 10010; int vis[maxn]; int y[maxn]; vector G[maxn]; int n; bool dfs(int u) { for(int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if(vis[v]) continue; vis[v] = true; ...
分类:其他好文   时间:2014-06-15 18:34:38    阅读次数:186
POJ 3278 Catch That Cow(BFS 剪枝)
题目链接:http://poj.org/problem?id=3278 这几次都是每天的第一道题都挺顺利,然后第二道题一卡一天。 = =,今天的这道题7点40就出来了,不知道第二道题在下午7点能不能出来。0 0 先说说这道题目,大意是有个农夫要抓牛,已知牛的坐标,和农夫位置。而且农夫有三种移动方式,X + 1,X - 1,X * 2,问最少几步抓到牛。 开始认为很简单的,三方向的BFS就能顺...
分类:其他好文   时间:2014-06-15 16:42:30    阅读次数:232
dfs模版
dfs#include #include char Map[16][16];int mv[16][16];//mv[i][j] == 0 没有被访问//mv[i][j] == 1 已经被访问struct N{int x,y;} ;int jx[] = { 0,-1, 0, 1};int jy[] =...
分类:其他好文   时间:2014-06-13 17:45:35    阅读次数:263
三维bfs(HUD1253胜利大逃亡)
#include #include int map[51][51][51];int v[51][51][51];int a,b,c,t11;struct node{ int x,y,z,ans;}q[200001];int jx[6]={0,0,0,0,-1,1};int jy[6]={0,0...
分类:其他好文   时间:2014-06-13 17:10:39    阅读次数:157
Depth-first Search(DFS)
There are generally two methods to write DFS algorithm, one is using recursion, another one is using stack. (reference from Wiki Pedia)Pseudocode for ...
分类:其他好文   时间:2014-06-13 08:39:34    阅读次数:218
Leetcode: Letter Combinations of a Phone Number
像这种DFS的题目,常见的写法无外乎两种,使用recursion, 或者用Stack。本文采用了stack的方式。做完后积累的经验有:像这种在一个ArrayList里面罗列可能的path的题目,recursion的参数一般包括:包含最终结果的集合(ArrayList),input(String),递...
分类:其他好文   时间:2014-06-13 08:34:10    阅读次数:220
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!