
DFS
文章平均质量分 81
J_Sure
唯苦修深思方能顿悟
展开
-
AOJ-AHU-OJ-460 Prime Ring Problem(栈)
Prime Ring ProblemTime Limit: 15000 ms Memory Limit: 64 MBDescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and th原创 2014-03-04 19:32:55 · 1194 阅读 · 0 评论 -
USACO-cha2-sec2.1 Healthy Holsteins
Healthy HolsteinsBurch & KolstadFarmer John prides himself on having the healthiest dairy cowsin the world. He knows the vitamin content for one scoop of eachfeed type and the minimum daily vitami原创 2014-07-28 00:32:21 · 1052 阅读 · 0 评论 -
USACO-cha2-sec2.1 The Castle
The CastleIOI'94 - Day 1In a stroke of luck almost beyond imagination, Farmer John was sent a ticket to the Irish Sweepstakes (really a lottery) for his birthday. This ticket turned out to have on原创 2014-07-15 13:43:14 · 1158 阅读 · 0 评论 -
Codeforces-258B Little Elephant and Elections
B. Little Elephant and Electionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere have recently been elections i原创 2014-08-22 23:28:10 · 992 阅读 · 0 评论 -
HDU-1198 Farm Irrigation
Farm IrrigationTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem DescriptionBenny has a spacious farm land to irrigate. The farm land is a rectan原创 2014-08-27 16:24:10 · 798 阅读 · 0 评论 -
HDU-OJ-1010 Tempter of the Bone
Tempter of the BoneTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem DescriptionThe doggie found a bone in an ancient maze, which fascinated him a原创 2014-03-20 08:22:02 · 1036 阅读 · 0 评论 -
【二分答案+枚举】AOJ-215 Mountain Walking
Mountain WalkingTime Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBJudge By CaseDescriptionFarmer John and Bessie the cow have embarked on one of those 'active' vaca原创 2014-09-29 19:24:53 · 898 阅读 · 0 评论 -
POJ-3684 Labeling Balls
Labeling BallsTime Limit: 1000MS Memory Limit: 65536KDescriptionWindy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 toN in s原创 2014-08-08 11:17:44 · 904 阅读 · 0 评论 -
POJ-1128 Frame Stacking
Frame StackingTime Limit: 1000MS Memory Limit: 10000KDescriptionConsider the following 5 picture frames placed on an 9 x 8 array......... ........ ........ ........ .CCC...原创 2014-08-07 20:59:35 · 885 阅读 · 0 评论 -
【DFS|暴力】USACO-cha1-sec1.3 Wormholes
WormholesFarmer John's hobby of conducting high-energy physics experiments on weekends has backfired, causing N wormholes (2 <= N <= 12, N even) to materialize on his farm, each located at a disti原创 2014-11-22 21:24:37 · 1243 阅读 · 0 评论 -
【DFS】AHU-448 有趣的矩阵
AHU-448 有趣的矩阵: http://icpc.ahu.edu.cn/OJ/Problem.aspx?id=448题意:给出N行M列的1组成的矩阵,找出这样一个M列的子矩阵,它的每一列有且仅有一个'1'。前言:对DFS没有清晰的掌握,很难做对这一题!原创 2014-11-30 00:35:30 · 1175 阅读 · 0 评论 -
【记忆化搜索】POJ-1141 Brackets Sequence
上次用自底向上递推的姿势Copy-Study了这道题的题解。但是还有一个个人觉得更容易接受的姿势——记忆化搜索。原创 2014-05-03 22:22:24 · 1926 阅读 · 2 评论 -
POJ-1270 Following Orders
Following OrdersTime Limit: 1000MS Memory Limit: 10000KDescriptionOrder is an important concept in mathematics and in computer science. For example, Zorn's Lemma states: ``a原创 2014-08-07 21:57:04 · 993 阅读 · 0 评论 -
POJ-1351 Number of Locks
Number of LocksTime Limit: 1000MS Memory Limit: 10000K DescriptionIn certain factory a kind of spring locks is manufactured. There are n slots (1 < n < 17, n is原创 2014-05-04 22:45:38 · 1223 阅读 · 0 评论 -
AOJ-AHU-OJ-61 Lake Counting(递归)
Lake Counting Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB Judge By Case DescriptionDue to recent rains, water has pooled in various places in Farmer John's fiel原创 2014-03-01 10:12:05 · 1175 阅读 · 0 评论 -
AOJ-AHU-OJ-455(POJ-1088) 滑雪
滑雪Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBDescriptionMichael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组原创 2014-03-06 09:41:37 · 1244 阅读 · 0 评论 -
POJ-1579 Function Run Fun
Function Run FunTime Limit: 1000MS Memory Limit: 10000K DescriptionWe all love recursion! Don't we? Consider a three-parameter recursive function w(a, b, c)原创 2014-04-20 18:30:40 · 986 阅读 · 0 评论 -
Round #186 (Div.2) Ilya and Matrix
C. Ilya and Matrixtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIlya is a very good-natured lion. He likes maths. O原创 2014-07-29 12:16:29 · 805 阅读 · 0 评论 -
ZOJ-1008 Gnome Tetravex
Gnome TetravexTime Limit: 10 Seconds Memory Limit: 32768 KB Hart is engaged in playing an interesting game, Gnome Tetravex, these days. In the game, at the beginning, the player is give原创 2014-08-01 10:44:18 · 948 阅读 · 0 评论 -
USACO-cha1-sec1.5 Superprime Rib
Superprime RibButchering Farmer John's cows always yields the best prime rib. You can tell prime ribs by looking at the digits lovingly stamped across them, one by one, by FJ and the USDA. Farmer原创 2014-07-07 22:18:41 · 1009 阅读 · 0 评论 -
搜索的优化算法——剪枝
原文地址http://princetonboy.ycool.com/post.2805302.html【摘要】本文讨论了搜索算法中“剪枝”这一常见的优化技巧.首先由回溯法解决迷宫问题展开论述,介绍了什么是剪枝;而后分析剪枝的三个原则正确、准确、高效,并分别就剪枝的两种思路:可行性剪枝及最优性剪枝,结合例题作进一步的阐述;最后对剪枝优化方法进行了一些总结.在竞赛中,我们有时会碰到一些转载 2014-03-18 21:21:14 · 2807 阅读 · 0 评论 -
AOJ-AHU-OJ-460 Prime Ring Problem(递归)
上次我使用栈讲解了素数环问题,很明显,尽管栈理解起来比较形象,而且不害怕数据范围过大导致的栈溢出问题。但是代码太冗长费时消耗精力。如果对递归的理解比较深刻。我们尝试一下使用递归,简单的解决这个简单的问题。要知道,递归调用本身是利用内存中的栈来保存本层递归结束之前的局部变量,以保证局部变量在本层递归结束时可以使用。#include #include int n;int vis[20], a原创 2014-03-04 19:54:07 · 1195 阅读 · 0 评论 -
AOJ-AHU-OJ-460 Prime Ring Problem(巩固)
上次使用递归完成了素数环问题,优化也做的还可以。主要思想是变量next,fath。递归开始的时候,next作为将要填入数字的位置,将fath保存到素数环中,然后访问此结点。判断将要填入的位置是否是n,为n表示素数环将要填满,首尾相接成功的话,打印素数环,return。而核心部分,就是For i : 1~n { 符合条件则: DFS(next+1, i) // i 作为局部变量存原创 2014-03-07 17:50:16 · 940 阅读 · 0 评论 -
HDU-OJ-1175 连连看
连连看Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem Description“连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过原创 2014-03-11 19:53:03 · 1115 阅读 · 0 评论 -
AOJ-AHU-OJ-453 棋盘问题
棋盘问题Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBDescription在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案CInpu原创 2014-03-11 20:23:17 · 1110 阅读 · 0 评论 -
AOJ-AHU-OJ-453 棋盘问题(位压缩)
上次我们DFS解决了棋盘问题。但是一跑……140+ms QAQ 看到别人20+ms AC了,深感愧疚。这次我们对棋盘问题的解决方式做空间和时间上的优化。让它优美地AC1.考虑空间问题。我们把棋盘作为地图保存了下来。有的地方是0可以放置棋子,有的地方是-1不能放置棋子。而且还做了每列的标记,放了棋子则该标记为1。我们发现,0/1 这个计算机唯一认识的两个符号是解决该问题的关键。“位运算”原创 2014-03-11 20:41:57 · 1155 阅读 · 0 评论 -
AOJ-AHU-OJ-595 撒哈拉大冒险(栈)
撒哈拉大冒险Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBTotal Submission: 193 Submission Accepted: 14Description在撒哈拉大沙漠中,有一个神奇的迷宫,那是所有冒险,探索者都想要破解的圣地。迷宫是由多块相同的子迷原创 2014-03-22 13:43:17 · 1490 阅读 · 0 评论 -
AOJ-AHU-OJ-61 Lake Counting(栈)
上次分享了我在白书当中学习到的DFS,使用了递归的思想。DFS本身是一个栈式数据结构,对于图,只是将其转化为数据进行操作。并没有使用Stack,但是递归本身就是将局部变量存储到栈帧,当中。对于很大的数据范围,栈容易发生溢出,导致出错。下面用手写栈代替递归调用。代码如下:#include #include int mat[110][110], vis[110][110];int sta原创 2014-03-02 21:39:29 · 1324 阅读 · 0 评论 -
AOJ-AHU-OJ-673 聪明的输入法
聪明的输入法Time Limit: 10000 ms Case Time Limit: 2000 ms Memory Limit: 128 MBDescription众所周知,讯飞输入法具备强大的学习功能,对于用户来说,感觉输入法像一个会学习的机器人,比如,当用户第一次输入“sxl”,输入法第一个提示“少写了”,如果用户选择“睡醒了”,当第二次用户再原创 2014-04-09 21:34:08 · 1354 阅读 · 0 评论 -
POJ-1163 The Triangle 「数字三角形」(dfs+记忆化)
题目+自上至下DP解法:原创 2014-04-21 20:16:03 · 1945 阅读 · 0 评论 -
ZOJ-1004(AOJ-466) Anagrams by Stack
Anagrams by StackTime Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBDescriptionHow can anagrams result from sequences of stack operations? There are two sequences of stack o原创 2014-03-18 20:10:04 · 1257 阅读 · 0 评论 -
Round #189 (Div.2) B. Ping-Pong (Easy Version)
B. Ping-Pong (Easy Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this problem at each moment you have a原创 2014-07-25 15:11:53 · 1388 阅读 · 0 评论 -
USACO-cha1-sec1.4 Mother's Milk
Mother's MilkFarmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty原创 2014-07-04 19:33:04 · 1115 阅读 · 0 评论 -
USACO-cha1-sec1.5 Checker Challenge
Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more原创 2014-07-05 15:24:37 · 921 阅读 · 0 评论 -
HDU-OJ-2553 N皇后问题(打表/位运算)
N皇后问题Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem Description在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定原创 2014-04-13 00:38:27 · 1980 阅读 · 0 评论 -
AOJ-AHU-OJ-189 最长递增子序列(DFS)
最长递增子序列Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBDescription有n个互不相同的整数an若存在一个数列bm其中对于任何1 满足bi i+1 且 abi bi+1则称abn为an的一个递增子序列试求出给定序列的最长递增子序列长度Input本题原创 2014-03-12 14:30:40 · 1188 阅读 · 0 评论 -
【容斥原理】AOJ-557 Redraiment猜想2
Redraiment猜想2Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBDescriptionredraiment在家极度无聊,于是找了张纸开始统计素数的个数。 设函数f(n)返回从1->n之间素数的个数。 redraiment发现: f(1) = 0原创 2014-04-01 13:43:55 · 2215 阅读 · 0 评论