码迷,mamicode.com
首页 >  
搜索关键字:bfs dfs    ( 14889个结果
poj 1699 Best Sequence(dfs)
http://poj.org/problem?id=1699 题意:给出n个只含A,C,G,T的字符串,要求能把这n个字符串组合起来的最短长度。 思路:预处理一下,a[i][j]表示将第j个字符串连接到第i个字符串后面增加的长度,那么我们需要找出这样一个序列1,2....n满足a[1][2] + a[2][3] + ...+a[n-1][n]的最小值。DFS就OK了,任选一个字...
分类:其他好文   时间:2014-06-08 17:49:21    阅读次数:199
HDU 1495 非常可乐 (BFS)
问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目大意:一个瓶子容积s,两个杯子容积分别n,m,并且都没有刻度(不能比对噢!)。相互倒水,求平分的他们的最少倒水次数。 思路:暴力搜索吧。并且求最少,(即最优解),随意上BFS; 思考:状态,转移过程,怎么剪纸。 惨痛的debug,我不解释了。...
分类:其他好文   时间:2014-06-08 15:48:26    阅读次数:234
poj 3411 Paid Roads(dfs,可重复访问节点)
http://poj.org/problem?id=3411 大致题意:n个城市由m条公路连接,两个城市之间可能有多条公路连接。经过每条公路都需要收费,对于城市a,b,若之前经过城市c那么只需交p元钱,否则交r元钱。问从城市1到n的最小花费。 思路:由于经过每条公路的收费有两种方式,那么有的城市可能要经过多次,以便获得更小的花费,但也有可能出现有环的情况,那么该城市经过多次只会...
分类:其他好文   时间:2014-06-08 15:27:22    阅读次数:145
Unique Binary Search Trees II
题目 Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. ...
分类:其他好文   时间:2014-06-08 15:15:26    阅读次数:223
POJ 2965 The Pilots Brothers' refrigerator (DFS)
题目:http://poj.org/problem?id=2965 也是以前就做过的题目,这次居然遇到了问题搞了一天。 关于最小步骤很容易就出来,DFS就可以,但是每一步是什么怎么也出不来了 DFS本质就是利用栈暴力,当出现正确结果的时候其过程都在栈中,我一直努力想还原这个栈,未果 然后思路大乱,然后问了RE,才发现根本不用这么麻烦,只需要建个存储步骤数组,在改变元素的时候记录并不停更新就...
分类:其他好文   时间:2014-06-08 14:51:49    阅读次数:242
poj 1724 ROADS(dfs)
http://poj.org/problem?id=1724 大致题意:N个城市由R条单向路连通,每条路(S,D)之间有两个因素:路的长度L和路的花费T。现要从城市1到达城市N,求花费在K以内的最短路程。 思路:很明显的dfs(他们都说很明显的spfa。。。)。不过dfs有几点注意的地方: 建立邻接表不能用vector存,要用链表的形式,采用头插法。 dfs的时候,在递归节...
分类:其他好文   时间:2014-06-08 14:41:32    阅读次数:243
Restore IP Addresses
题目 Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given "25525511135", return ["255.255.11.135", "255.255.111.3...
分类:其他好文   时间:2014-06-08 10:37:47    阅读次数:273
2-SAT模版
const int maxn = 100010; int n, m; vector G[maxn*2]; bool mark[maxn*2]; int S[maxn*2], c; int a[maxn], b[maxn], sum; bool dfs(int x) { if(mark[x^1]) return false; if(mark[x]) return true; mark...
分类:其他好文   时间:2014-06-08 10:31:01    阅读次数:198
Maximum Depth of Binary Tree
题目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 方法 使用DFS对树进行遍...
分类:其他好文   时间:2014-06-08 10:26:33    阅读次数:207
POJ - 1324 Holedox Moving
题意:贪吃蛇的题目 思路:BFS+状态的记录,坑了无数发,#include #include #include using namespace std; const int MAXN = 500000; bool flag[8],vis[25][25],mp[21][21][16384]; int n,m,l; int xx[4]={-1,0,1,0}; // up,right,dow,left...
分类:其他好文   时间:2014-06-08 10:13:19    阅读次数:204
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!