dfs
文章平均质量分 75
h1021456873
这个作者很懒,什么都没留下…
展开
-
HDU 1258 Sum It Up (DFS)
Problem DescriptionGiven a specified total t and a list of n integers, find all distinct sums using numbers from the list that add up to t. For example, if t=4, n=6, and the list is [4,3,2,2,1,1],原创 2015-08-12 17:20:58 · 391 阅读 · 0 评论 -
codeforce 723d Lakes in Berland(暴力DFS)
The map of Berland is a rectangle of the size n × m, which consists of cells of size1 × 1. Each cell is either land or water. The map is surrounded by the ocean.Lakes are the maximal regions of原创 2016-11-13 16:00:48 · 243 阅读 · 0 评论 -
1115. Counting Nodes in a BST (构建二叉排序树,输出最后两层的节点数)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than or equal to the node's key.原创 2016-12-08 18:58:41 · 463 阅读 · 0 评论 -
PAT 1104 Sum of Number Segments (暴力DFS)
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence {0.1, 0.2, 0.3, 0.4}, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3)原创 2016-12-09 14:35:50 · 283 阅读 · 0 评论 -
codeforces 734 E. Anton and Tree (黑红树,缩点+dfs)
Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph.There are n vertices in the tree, each of them is painted black or white. Anton doesn't li原创 2016-11-27 20:08:13 · 514 阅读 · 0 评论 -
codeforce B. Chloe and the sequence (递归)
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.Let's consider the原创 2016-12-17 20:43:42 · 376 阅读 · 0 评论 -
HDU 5927 Auxiliary Set 最近公共祖先 (dfs)
Given a rooted tree with n vertices, some of the vertices are important. An auxiliary set is a set containing vertices satisfying at least one of the two conditions:∙It is an important ver原创 2017-03-04 15:48:53 · 221 阅读 · 0 评论 -
POJ 1321 棋盘问题 (DFS+回溯)
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n 当为-1 -1时表示输入结束原创 2017-03-12 23:28:43 · 249 阅读 · 0 评论 -
POJ - 3984 迷宫问题 (BFS+DFS)
定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。 Input一个5原创 2017-03-13 00:09:52 · 297 阅读 · 0 评论 -
POJ2488 【骑士游历】( dfs + 回溯 )
DescriptionBackground The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is原创 2017-04-07 20:17:58 · 954 阅读 · 0 评论 -
CSU 1513 Kick the ball! 点球大战(DFS)
题意:点球大战,轮流每队点射5个球,A先踢。如果当前比分已经能直接让比赛胜利接下来的球就不需要踢了。问最后的得分是题所给出的得分的概率#include#include#include#include#includeusing namespace std;double a[6],b[6],ans;int scord1,scord2;void dfs(int rt,doub原创 2017-03-15 21:21:43 · 444 阅读 · 0 评论 -
poj1190 神剪枝啊 生日蛋糕 (dfs)
7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体。 设从下往上数第i(1 Ri+1且Hi > Hi+1。 由于要在蛋糕上抹奶油,为尽可能节约经费,我们希望蛋糕外表面(最下一层的下底面除外)的面积Q最小。 令Q = Sπ 请编程对给出的N和M,找出蛋糕的制作方案(适当的Ri和Hi的值),使S最小。 (除Q外,以上所有数据皆为正原创 2017-03-25 13:52:49 · 259 阅读 · 0 评论 -
UVA 11882 Biggest Number (搜索+剪枝(dfs+bfs))
题意:在一个R行C列(2≤R,C≤15,R∗C≤30)的矩阵里有障碍物和数字格(包含1~9的数字)。你可以从任意一个数字格出发,每次沿着上下左右之一的方向走一格,但不能走到障碍格中,也不能重复经过一个数字格,然后把沿途经过的所有数字连起来,如图所示。如图可以得到9784,4832145等整数。问:能得到的最大整数是多少?(本段摘自《算法竞赛入门经典(第2版)》)分析: 枚举起点原创 2017-04-02 20:38:32 · 591 阅读 · 0 评论 -
HDU 5546 放棋 (dfs,细心)
题意:一个9*9的棋盘,判断能否把接下来的一个x,放到地图中的一个空白位置上。 使得出现一个联通块内的o,找不到任何一个可以扩展的联通块位置'.' 思路:枚举o周围的x放置,如果周围可放置数为1,表示成功,注意重复记录,所以用两个数组个标记要注意的是!!!! 枚举‘o’联通块周围的‘.’空地时,要判重,不然要wrong,,哎哎哎,不够细心Yu Zhou like原创 2017-03-27 00:41:30 · 365 阅读 · 0 评论 -
POJ 2531 Network Saboteur(dfs+剪枝)
题意就是把节点分成A、B两组,节点间距C给了,要求解分组的方法,使得∑Cij (i∈A,j∈B)最大。#include#include#include#include#includeusing namespace std;const int inf = 0x3f3f3f3f;int edge[22][22],vis[22];int flag,n;void dfs(原创 2017-04-18 10:47:48 · 325 阅读 · 0 评论 -
POJ 1416 Shredding Company (DFS)
题目翻译:公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值。比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1、2、34、6。因为这样所得到的和43 (= 1 + 2 + 34 + 6) 是所有可能中最接近而不超过50的。(比如1, 23, 4, 和6 就不可以,因为它们的和不如43接近50,而12, 34,原创 2017-04-18 19:36:21 · 316 阅读 · 0 评论 -
POJ - 1129 Channel Allocation (dfs,四色定理)
题目翻译:当一个广播电台在一个非常大的地区,广播站会用中继器来转播信号以使得每一个接收器都能接收到一个强烈的信号。然而,每个中继器必须慎重选择使用,使相邻的中继器不互相干扰。如果相邻的中继器使用不同的频道,那么就不会相互干扰。由于无线电频道是一有限的,一个给定的网络所需的中继频道数目应减至最低。编写一个程序,读取一个中继网络,然后求出需要的最低的不同频道数。题解:当一个点染原创 2017-04-18 21:22:58 · 327 阅读 · 0 评论 -
POJ 1011 最小的木棒 (dfs+剪枝|| 搜索好题)
Description乔治拿来一组等长的木棒,将它们随机地砍断,使得每一节木棍的长度都不超过50个长度单位。然后他又想把这些木棍恢复到为裁截前的状态,但忘记了初始时有多少木棒以及木棒的初始长度。请你设计一个程序,帮助乔治计算木棒的可能最小长度。每一节木棍的长度都用大于零的整数表示。Input输入包含多组数据,每组数据包括两行。第一行是一个不超过64的整数,表示砍断之后共有多少节原创 2016-03-15 00:36:24 · 1562 阅读 · 1 评论 -
蓝桥杯 牌型种数 (暴力||dfs)
牌型种数小明被劫持到X赌城,被迫与其他3人玩牌。一副扑克牌(去掉大小王牌,共52张),均匀发给4个人,每个人13张。这时,小明脑子里突然冒出一个问题:如果不考虑花色,只考虑点数,也不考虑自己得到的牌的先后顺序,自己手里能拿到的初始牌型组合一共有多少种呢?思路:循环遍历每个点数所选择的张数,每个点数最多可以选4张,最少可以选0张即不选,每当牌总数达到13张则计数。答案原创 2016-03-13 11:05:44 · 6359 阅读 · 4 评论 -
HUST 1600 由4,8组成的数且能整除48 (dfs枚举)
Isun loves digit 4 and 8 very much. He thinks a number is lucky only if the number satisfy the following conditions: 1. The number only consists of digit 4 and 8. 2. The number multipl原创 2016-03-07 19:03:10 · 385 阅读 · 1 评论 -
HDU 1015 Safecracker (很棒的一道DFS)
题意:输入一个数target 和一个字符串 s,在字符串 s 找出一个由5个字符组成的最大字符串使得v - w^2 + x^3 - y^4 + z^5 = target ;Problem Description=== Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein safe原创 2015-08-14 13:13:19 · 702 阅读 · 0 评论 -
zoj 1562 Oil Deposits (DFS)
DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid原创 2015-07-24 19:32:28 · 439 阅读 · 0 评论 -
POJ 1979 Red and Black (DFS)
/*简单的dfs题,注意map数组清零注意题目中地图输入的行列顺序,陷阱!*/DescriptionThere is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From原创 2015-07-26 12:24:20 · 335 阅读 · 0 评论 -
ZOJ 2412 Farm Irrigation (DFS+模拟)
Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has a different type o原创 2015-07-25 15:09:31 · 362 阅读 · 1 评论 -
hdu 1010 Tempter of the Bone (DFS)
Problem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He原创 2015-07-24 19:29:33 · 253 阅读 · 0 评论 -
HDU 2553 N皇后问题 (DFS_回溯)
Problem Description在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。 Output原创 2015-08-20 18:32:14 · 546 阅读 · 0 评论 -
POJ 1088 滑雪 (递归+记忆化搜索)
DescriptionMichael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 2原创 2015-09-10 20:31:35 · 424 阅读 · 1 评论 -
POJ 2385 Lake Counting (dfs_连通性)
DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains原创 2015-09-13 16:32:39 · 442 阅读 · 1 评论 -
AOJ Property Distribution (dfs_连通性)
タナカ氏が HW アールの果樹園を残して亡くなりました。果樹園は東西南北方向に H×W の区画に分けられ、区画ごとにリンゴ、カキ、ミカンが植えられています。タナカ氏はこんな遺言を残していました。果樹園は区画単位でできるだけ多くの血縁者に分けること。ただし、ある区画の東西南北どれかの方向にとなりあう区画に同じ種類の果物が植えられていた場合は、区画の境界が分からないのでそれらは 1 つの大きな原创 2015-09-29 21:59:15 · 568 阅读 · 0 评论 -
POJ 3984 迷宫问题 (DFS+BFS)
Description定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线原创 2015-09-13 19:12:23 · 583 阅读 · 1 评论 -
HDU Prime Ring Problem (DFS+素数打表)
Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime原创 2015-08-14 14:40:49 · 609 阅读 · 0 评论 -
cf C. Kefa and Park (树的dfs)
Kefa decided to celebrate his first big salary by going to the restaurant.He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also原创 2015-09-23 20:35:37 · 727 阅读 · 5 评论 -
51nod 1416 两点 (dfs)
福克斯在玩一款手机解迷游戏,这个游戏叫做”两点”。基础级别的时候是在一个n×m单元上玩的。像这样: 每一个单元有包含一个有色点。我们将用不同的大写字母来表示不同的颜色。这个游戏的关键是要找出一个包含同一颜色的环。看上图中4个蓝点,形成了一个环。一般的,我们将一个序列 d1,d2,...,dk 看成一个环,当且仅当它符合下列条件时:1. 这k个点不一样,原创 2016-01-25 21:47:24 · 939 阅读 · 0 评论 -
HDU 找出直系亲属 (dfs+vector)
Problem Description如果A,B是C的父母亲,则A,B是C的parent,C是A,B的child,如果A,B是C的(外)祖父,祖母,则A,B是C的grandparent,C是A,B的grandchild,如果A,B是C的(外)曾祖父,曾祖母,则A,B是C的great-grandparent,C是A,B的great-grandchild,之后再多一辈,则在关系上加一个grea原创 2016-02-05 14:34:07 · 626 阅读 · 0 评论 -
HDU 1520 Anniversary party (树形dp,dfs+dp)
今天开始做老师给的专辑,打开DP专辑 A题 Rebuilding Roads 直接不会了,发现是树形DP,百度了下了该题,看了老半天看不懂,想死的冲动都有了~~~~最后百度了下,树形DP入门,找到了 poj 2342 Anniversary party 先入门一下~题意:某公司要举办一次晚会,但是为了使得晚会的气氛更加活跃,每个参加晚会的人都不希望在晚会中见到他的直接上司,原创 2016-02-22 10:57:21 · 353 阅读 · 1 评论 -
51nod 1405 树的距离之和 (两次dfs,树形dp)
给定一棵无根树,假设它有n个节点,节点编号从1到n, 求任意两点之间的距离(最短路径)之和。Input第一行包含一个正整数n (n <= 100000),表示节点个数。后面(n - 1)行,每行两个整数表示树的边。Output每行一个整数,第i(i = 1,2,...n)行表示所有节点到第i个点的距离之和。Input示例41 23 24 2原创 2016-02-21 23:36:41 · 476 阅读 · 1 评论 -
洛谷 P1219 八皇后 (dfs)
题目描述检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行、每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子。上面的布局可以用序列2 4 6 1 3 5来描述,第i个数字表示在第i行的相应位置有一个棋子,如下:行号 1 2 3 4 5 6列号 2 4 6 1 3 5这只是跳棋放置的一个解。请编一个程原创 2017-05-23 00:33:58 · 460 阅读 · 2 评论