
dfs
TIMELIMITE
Time is not enough. I must hurry up !
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 51 N皇后 回溯
n皇后回溯法原创 2022-07-01 15:52:58 · 339 阅读 · 0 评论 -
LeetCode 79 单词搜索
// 记录起点,然后dfsclass Solution { int[] dx = {-1 , 0, 1, 0}; int[] dy = {0, 1, 0, -1}; int n; int m; boolean[][] vis; public boolean exist(char[][] board, String word) { ...原创 2019-08-25 18:43:24 · 263 阅读 · 0 评论 -
LeetCode 40 组合总和 II dfs
// 跟上题类似,只是需要去重方面考虑的多一些// 开始暴力去重,发现效率很低...// 后来参考大牛们的博客才发现,原来只要在每次递归的时候// 就可以去重,比如:// 1 1 2 2 3// 1放入 ,第二个1在这轮循环中不需要再放入,注意是这轮循环// 递归不到家....哎...继续加油!class Solution { boolean[] flag = nul...原创 2019-05-06 21:19:57 · 245 阅读 · 0 评论 -
LeetCode 39 组合总和 dfs
// 我以为有啥好方法,结果...都是dfs暴力class Solution { public List<List<Integer>> combinationSum(int[] condidates, int target){ List<List<Integer>> res = new ArrayList<&g...原创 2019-05-06 19:45:16 · 236 阅读 · 0 评论 -
LeetCode 37 解数独 DFS
// 逐行填入数字,需要判断状态,这里借助别人的思路// 跟之前判断数独合法类似,需要用到辅助数组// row[i][k]表示第i行数字k是否使用// col[j][k]表示第j列数字k是否使用// metrix[x][k]表示第x个小9宫格中k是否使用编码方式// 0 1 2// 3 4 5// 6 7 8// 所以i和j与x的对应关系是 x = i / 3 * 3 + j /...原创 2019-05-05 22:52:48 · 238 阅读 · 0 评论 -
hdu 5877 Weak Pair dfs + 线段树(or树状数组)
// hdu 5877 Weak Pair dfs + 线段树(or树状数组)//// 题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5877//// 题目大意:// n个节点到有根树,u是v的祖先,每个节点有个权值a[u].求// a[u] * a[v] <= k的有序对的数量。//// 解答://原创 2016-09-10 22:48:26 · 743 阅读 · 0 评论 -
hdu 5325 Crazy Bobo dfs
// hdu 5325 Crazy Bobo//// 题目大意:// // 给你一棵树,树上每个节点都有一个权值w,选择尽可能多的节点,// 这些节点相互联通,并且按照权值升序排序之后得到节点编号,// 需相邻节点之间的任意节点都要大于较小的节点。// // 解题思路:// 对于原创 2015-07-29 11:42:55 · 949 阅读 · 2 评论 -
九宫格练习 9*9数独游戏
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include原创 2015-05-19 16:53:42 · 4576 阅读 · 0 评论 -
农夫过河问题 简单的搜索
// 用一个二进制串表示状态0,表示东西或者人在河的这边// 1表示东西或者人在河的另一边// 比如0000表示都在起始的位置,1111表示都到了对岸// 通过状态的转移,来找到路径#include #include #include #include using namespace std;const int maxn = 100;const int inf = 0x7f7原创 2015-06-17 01:03:50 · 2490 阅读 · 0 评论 -
poj 3009 Curling 2.0 dfs回溯
// poj3009 Curling 2.0// dfs水题,开始的时候没有想到在走了10步以后就不走了这个重要的剪枝,// 结果tle了。。。// 后来想了个vis数组记录走过的路径,结果发现并不能这样标记,因为每个点可能// 走多次,所以这样是不对的//// 哎,继续练吧,水题都差不多搜了一个小时,哎,。。。#include #include #include #incl原创 2015-05-15 15:31:40 · 819 阅读 · 0 评论 -
BestCoder #37 Rikka with string (hdu 5205)
// 这题一开始看的时候觉得就是取最右边的问号,依次从大到小枚举// 注意没有?和?在中间的情况特判,结果wa了十一发,还是没有找到// 错误在哪里,看了一下discuss里面的数据发现5 b??ab这组用我先开始// 的思路是跪了的。我的会输出QwQ。。。//// 然后看了看大牛们的思路,发现自己所谓的最右边是错的,这题要求字典序最小// 可以先全部把?填成a,判断是否回文,//原创 2015-04-13 12:25:48 · 932 阅读 · 0 评论