![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
搜索-回溯法
lab104_yifan
这个作者很懒,什么都没留下…
展开
-
UVA 539 The Settlers of Catan
UVA 539 The Settlers of Catan题意 输入n, 再输入n组数据,每组数据有两个节点,表示两点可以相连,每两个可以相连的节点长度为1,找出该图中最长的路径输出值, 注意:节点可以重复经过, 边不能重复思路 直接dfs,每个节点都进行一次dfs,找出每个借点连接的最大路径,然后进行比较输出最大的那个代码#include #incl原创 2013-07-09 08:48:13 · 1484 阅读 · 1 评论 -
UVA 211 - The Domino Effect(dfs+剪枝)
The Domino Effect A standard set of Double Six dominoes contains 28 pieces (called bones) each displaying two numbers from 0 (blank) to 6 using dice-like pips. The 28 bones, which are un原创 2014-01-17 13:42:07 · 1744 阅读 · 0 评论 -
UVA 1354 - Mobile Computing(暴力枚举)
There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful stones on the planet, and the Yaen people love to collect them. They bring the stones back home and mak原创 2014-02-26 11:27:30 · 2138 阅读 · 0 评论 -
10609 - Fractal (模拟,dfs)
Problem AFractalInput: Standard InputOutput: Standard OutputTime Limit: 3 Seconds A fractal is a rough or fragmented geometric shape that can be subdivided in parts, each of which is (at l原创 2014-02-27 12:35:30 · 1263 阅读 · 0 评论 -
ZOJ 3764 Easy billiards 月赛E题
Edward think a game of billiards is too long and boring. So he invented a new game called Easy billiards.Easy billiards has N balls on a brimless rectangular table in the beginning, and your goal is原创 2014-03-02 20:12:44 · 1546 阅读 · 0 评论 -
11782 - Optimal Cut(树形DP+记忆化搜索)
题目链接:11782 - Optimal Cut题意:按前序遍历给定一棵满二叉树,现在有k次,可以选k个节点,获得他们的权值,有两个条件:1、一个节点被选了,他的子节点就不能选了。2、最终选完后,根到所有叶子的路径上,都要有一个被选的节点。思路:树形dp,dp[u][k]代表在结点u,可以选k个节点,那么就分两种情况选u节点,dp[u][k] = node[u];选子节点之原创 2014-05-01 11:29:49 · 1244 阅读 · 0 评论 -
UVA 1548 - The Game of Master-Mind(dfs剪枝)
链接:1548 - The Game of Master-Mind题意:给定几个密码串的猜测情况,黑点代表位置和颜色完全匹配,白点代表颜色有出现过,位置不匹配,问密码的可能情况的最小字典序。思路:dfs暴力,然后剪枝,剪枝为黑点超过个数或者总数超过总数就直接返回。代码:#include #include #include using namespace std;const原创 2014-04-01 22:37:39 · 1593 阅读 · 0 评论 -
UVA 764 Pentominos(搜索)(未AC)
链接:764 - Pentominos题意:8X8格子上,4个点不能放,其余点可以放,然后12块拼图去找一种可以放的方案。思路:直接DFS去搜索了,加了些剪枝,还是过不了TLE了,答案跑起来感觉挺快的。有谁过了的求交流代码:#include #include #include #include #include #include #include #define原创 2014-04-05 13:11:43 · 1244 阅读 · 0 评论 -
UVA 649 - You Who?(搜索+位运算+剪枝)
链接:649 - You Who?题意:N个人,每个人都有一些认识的人,现在要求把这些人分成两堆,两堆人数差不超过1,然后要让两堆人两两认识,没两个人认识需要花费1分钟,要使得总花费时间最少,问方案。思路:每种情况的花费时间,肯定取决于那个对于分到的一堆人里面,不认识的人最多的那个人,然后利用位运算去记录每个人认识的人,还是利用位运算去枚举两堆的情况。搜索所有答案。加了几个时间才勉强跑原创 2014-04-05 17:03:42 · 1185 阅读 · 0 评论 -
UVA 690 Pipeline Scheduling (搜索+位运算+剪枝)
690 - Pipeline Scheduling题意:10个任务,5个通道,要求每个通道都能放下10个任务且不冲突,然后每个通道的放的方式间隔都是一样的,问最短需要时间。思路:利用位运算保存每个通道的放置方法,然后去深搜,要加剪枝。详细见代码代码:#include #include #define min(a,b) ((a)<(b)?(a):(b))#define原创 2014-04-08 16:01:02 · 2597 阅读 · 4 评论 -
UVA 586 - Instant Complexity(dfs)
UVA 586 - Instant Complexity题目链接题意:给定一些操作,问这些操作一共执行了多少步思路:按操作dfs下去,然后每次END的时候加上对应的幂次的个数,最后注意输出的几个坑点即可代码:#include #include int t, ans[15];char c[10], str[105];void dfs(int x,原创 2014-08-03 17:23:15 · 1144 阅读 · 0 评论 -
UVA 11748 - Rigging Elections(dfs)
UVA 11748 - Rigging Elections题目链接题意:n个人选举,给出m个人的投票人对于每个人的优先级,现在你想让第c个人赢,问能不能思路:对于两个人上场,如果a能赢b,就建一条a->b的边,然后问题其实就变成能否以c为根节点是一棵树,直接dfs一遍即可代码:#include #include #include using names原创 2014-08-28 01:04:45 · 1350 阅读 · 0 评论 -
UVA 10441 - Catenyms(欧拉道路)
UVA 10441 - Catenyms题目链接题意:给定一些单词,求拼接起来,字典序最小的,注意这里的字典序为一个个单词比过去,并不是一个个字母思路:欧拉回路,利用并查集判联通,然后欧拉道路判定,最后dfs输出路径代码:#include #include #include #include #include #include using nam原创 2014-08-27 23:28:58 · 1814 阅读 · 0 评论 -
UVA 10938 - Flea circus(dfs)
UVA 10938 - Flea circus题目链接题意:给定一棵树,然后每次询问两个点,问沿这两点路径走两点会相遇还是会穿过思路:每次询问,进行一次dfs,由于是一棵树,所以每个结点只需要遍历一遍就能找出路径了,记录下路径输出即可代码:#include #include #include #include using namespace std;原创 2014-09-11 22:23:10 · 1237 阅读 · 0 评论 -
Codeforces 34C Page Numbers(简单图论+DFS)
D. Road Maptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in Berland. Each city has it原创 2014-01-14 00:25:39 · 1994 阅读 · 0 评论 -
UVA 1374 - Power Calculus(迭代深搜)
Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multiplications:x2 = x x x, x3 = x2 x x, x4 = x3 x x, ... , x31 = x30 x x.The operation of squari原创 2013-12-28 02:00:55 · 2598 阅读 · 0 评论 -
UVA 817 - According to Bartjens(暴力搜索)
According to Bartjens The wide dissemination of calculators and computers has its disadvantages. Even students in technical disciplines tend to exhibit a surprising lack of calculating a原创 2013-12-27 13:44:20 · 2817 阅读 · 0 评论 -
UVA 10474 Where is the Marble?
UVA 10474 Where is the Marble?很水的一题。直接从小到大排序好,然后看要找哪个,找过去找出位置即可。。。还有一种方法,计数排序时间复杂度更低。。不过这题数据量不大没问题#include #include #include using namespace std;int n, m;int a[10005], b[10005]原创 2013-07-20 20:25:45 · 1911 阅读 · 0 评论 -
UVA639 Don't Get Rooked
UVA639 Don't Get Rooked类似八皇后问题,不过中间多了障碍物。。深搜回溯,标记放过的点,。然后利用标记的点进行判断能不能放入。#include #include int n;char map[10][10];int vis[10][10];int max;void dfs(int num){ if (max < num原创 2013-07-20 20:37:26 · 1040 阅读 · 0 评论 -
UVA 10344 23 out of 5
UVA 10344 23 out of 5找23点。。用深搜。。直到找到23点为止。。每个数字有3种情况 + - *找到5个数字就判断。。#include using namespace std;#include #include int num[5];int judge;void dfs(int star, int sum){ if原创 2013-07-20 20:39:40 · 1009 阅读 · 0 评论 -
UVA 216 Getting in Line
UVA 216 Getting in Line深搜回溯,找出最短的路径。。搜索过程中保存下路径。最后输出。。其实也可以用全排列的next_permutation 暴力找出最短。。#include #include #include int n;double x[10], y[10];int vis[10];int lu[10];int minlu[10];原创 2013-07-20 20:35:30 · 1060 阅读 · 0 评论 -
UVA 301 Transportation 。。有点需要思考的回溯、、
UVA 301 Transportation Transportation Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transp原创 2013-07-20 23:56:00 · 1775 阅读 · 0 评论 -
UVA 331 Mapping the Swaps
UVA 331 Mapping the Swaps题意。给一串数字。求其冒泡排序(最少次数的)方案的种数。。标准的深搜回溯每次交换值后进行一次judge。如果从小到大了,就种数加1.#include #include int min;int n;int num[5];int judge(){ for(int i = 0; i原创 2013-07-20 20:42:36 · 1028 阅读 · 0 评论 -
UVA 669 - Defragment(dfs)
Defragment You are taking part in the development of a ``New Generation'' operating system and the NG file system. In this file system all disk space is divided into N clusters of the eq原创 2013-12-28 22:49:17 · 1484 阅读 · 0 评论 -
UVA 798 - Tile Puzzle(暴力枚举)
Tile Puzzle In a puzzle a rectangular surface of width w and height h is split into a collection of rectangular tiles. The tiles with the same dimensions form a similarity group. Solving原创 2014-01-01 12:11:55 · 1875 阅读 · 0 评论 -
UVA 225 - Golygons(dfs回溯)
Golygons Imagine a country whose cities have all their streets laid out in a regular grid. Now suppose that a tourist with an obsession for geometry is planning expeditions to several su原创 2014-01-03 23:39:24 · 3644 阅读 · 3 评论 -
UVA 818 - Cutting Chains(暴力+dfs判环+位运算)
Cutting Chains What a find! Anna Locke has just bought several links of chain some of which may be connected. They are made from zorkium, a material that was frequently used to manufactu原创 2014-01-04 11:23:34 · 5520 阅读 · 2 评论 -
11127 - Triple-Free Binary Strings(dfs+位运算)
Problem JTriple-Free Binary Strings Input: Standard InputOutput: Standard Output A binary string consists of ones and zeros. Given a binary string T, if there is no binary string S such tha原创 2014-01-05 12:59:21 · 1248 阅读 · 0 评论 -
UVA 10318 - Security Panel(dfs+剪枝)
Problem GSecurity PanelInput: standard inputOutput: standard outputTime Limit: 2 secondsMemory Limit: 32 MB Advanced Control Mechanisms (ACM) produces sophisticated electronic locks and原创 2013-12-20 21:27:51 · 2076 阅读 · 0 评论 -
uva 524 - Prime Ring Problem(dfs)
Prime Ring Problem A ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of numbers in two adjacent circles s原创 2013-12-21 19:18:43 · 1196 阅读 · 0 评论 -
POJ 1321 棋盘问题(暴力dfs or DP)
POJ1321 棋盘问题题目链接题意:中文题不多说思路:本来是开二分图匹配的专题的,结果开错题开了这题- -,然后看了下数据范围,暴力爆过,额,不过没跑到0MS,于是又用状压DP搞了一发搞到0MS了代码:暴力:#include #include #include using namespace std;const int N = 10;i原创 2014-10-29 17:01:10 · 908 阅读 · 0 评论