
dfs
Healer66
他是谁啊?他究竟是什么身份啊?
展开
-
POJ - 1011- Sticks (dfs&&剪枝)
链接:http://poj.org/problem?id=1011题意:给出n根小棒的长度stick[i],已知这n根小棒原本由若干根长度相同的长木棒(原棒)分解而来。求出原棒的最小可能长度。思路:1、 由于所有棒子已降序排序,在DFS时,若某根棒子不合适,则跳过其后面所有与它等长的棒子;2、 最重要的剪枝:对于某个目标InitLen,在每次构建新的长度为InitLen的原...原创 2018-09-11 15:23:43 · 186 阅读 · 0 评论 -
HDU - 5547 - Sudoku (dfs)
思路:纯暴力会超时,每次填的时候需要判断当前行列是否满足情况,最后判断2x2的是否满足即可ps:一定不要忘了回溯#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <...原创 2019-08-05 19:06:31 · 391 阅读 · 0 评论 -
HDU - 5546 - Ancient Go (dfs)
题意:点代表空格,相同棋子上下左右相连为一个分量,当一个分量不与点相连的时候这个分量就是死的,题目先把o死的分量去除,再把x死的分量去除,这之后再下一个x问能不能使一个o分量dead,最后这个就是判断有没有o分量所连的点只有一个思路:搜索三次即可#include <iostream>#include <cstdio>#include <cmat...原创 2019-08-05 18:44:24 · 340 阅读 · 0 评论 -
HDU - 6228 - Tree (dfs)
思路:若想某个点被访问,则这个点的左右两端都得有不小于k个点。因此,dfs,得出某个点的一端点的数量,判断即可#include<bits/stdc++.h>using namespace std;const int maxn =2e5+10;int n,k,h[maxn],ans;vector<int> g[maxn];int dfs(int m)...原创 2019-04-19 19:48:48 · 230 阅读 · 0 评论 -
HDU - 1426 - Sudoku Killer (dfs)
思路:dfs即可,赋值前先判断是否可以#include <bits/stdc++.h>using namespace std;struct point{ int x, y;}p[81];int num, flag, G[10][10];int judge(int n, int k){ int i, j, x, y; for(i = 0;...原创 2019-04-17 12:05:23 · 239 阅读 · 0 评论 -
HDU - 1142 - A Walk Through the Forest (最短路+dfs)
题意:终点到B和A有多少条路径,且终点到B的距离小于A#include <bits/stdc++.h>using namespace std;const int maxn = 1e3 + 10;const int inf = 0x3f3f3f3f;int G[maxn][maxn];int dis[maxn];bool vis[maxn];int p[maxn...原创 2019-04-16 19:29:10 · 215 阅读 · 0 评论 -
UVALive - 8290-Capsules(dfs)
题意:给出方格大小以及某一些已填数字,需要我们自己填数字,要求,相同数字不相邻,包括斜的,在给定的区域内刚好用够1-n几个数字思路:搜索即可#include <bits/stdc++.h>using namespace std;const int maxn = 100;int ma[maxn][maxn],indexx[maxn][maxn],number[ma...原创 2019-02-03 22:39:08 · 278 阅读 · 0 评论 -
HDU - 5527 A - Too Rich (贪心&&dfs)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5527题意:给出硬币面值和数量,让你用数量最多的硬币凑出给定的数.思路:正反思考都行.正面想就是要尽可能多的用面值少的硬币,所以从面值大的开始考虑,假设把比它面值小的都选上后,看看需要补多少个当前面值硬币.反面就是想去掉尽量少的硬币,使得剩下的刚好满足要求.正:#in...原创 2018-10-29 22:04:21 · 191 阅读 · 0 评论 -
hdu-5952 Counting Cliques(dfs&&优化)
完全图概念题意:给一个无向图,N(0-100)个顶点,M(0-1000)条边,求图中顶点数为S(1-10)的完全图(任意两个顶点都有一条边相连)的个数。思路:最开始还以为是环,这锅sls得背啊哈哈哈哈。题解都在注释里了。#include <iostream>#include <cstring>#include <cstdio>#i...原创 2018-10-05 18:21:19 · 157 阅读 · 0 评论 -
UVALive - 8273—Assigning Frequencies (dfs)
题目链接:https://odzkskevi.qnssl.com/5a85a65abd98a64d2f1bf7440cfb6fb8?v=1535813894题意:给卫星设置频率,最多三种,告诉你哪些卫星之间不能是同一频率,问你是否能适当安排,以满足题意。思路:最多35个卫星,深搜即可。#include <bits/stdc++.h>using namespa...原创 2018-09-04 07:42:49 · 690 阅读 · 0 评论 -
Aizu - 1379 —Parallel Lines (dfs)
Given an even number of distinct planar points, consider coupling all of the points into pairs. All the possible couplings are to be considered as long as all the given points are coupled to one and ...原创 2018-09-05 08:09:31 · 473 阅读 · 0 评论 -
POJ - 1190 - 生日蛋糕 (深搜&&剪枝)
链接:http://poj.org/problem?id=1190思路:剪枝。1、从半径n+1开始2、当前已有表面积,加上剩余的预估最小表面积,若大于最优解,减掉。(什么是预估最小解?高度每次减一,半径也每次减一就是了,这个可以求出来)3、当前已有体积,加上剩余的预估最小体积,若大于最优解,减掉(同上)。4、搜索途中,若体积超出限制,减掉5.(目标体积-已有体积)/...原创 2018-09-11 08:24:03 · 210 阅读 · 0 评论 -
HDU - 6386 - Age of Moyu (BFS分层+DFS 或者 最短路+set)
题意:连续相同类型的边花费为1,走不同的边花费加一,求最少花费BFS:维护当前最少花费,每次往外扩展一步即可最短路:set记录到达改点的边的类型都有哪些(距离相同),如果出现更小的则清空,否则若相同,加入集合。 在进行距离更新时判断一下set里有没有当前类型的边即可BFS#include <bits/stdc++.h>using namespace std;...原创 2019-08-01 16:57:52 · 305 阅读 · 0 评论