
DFS
coldfresh
那我们开始吧
展开
-
棋盘问题(dfs)(poj-1321)
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。 Input 输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n 当为-原创 2017-04-17 20:50:18 · 515 阅读 · 0 评论 -
【51nod】最复杂的数 (简单搜索)
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数。 例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6。如果有多个数复杂度相等,输出最小的。 Input 第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 100) 第2 - T ...原创 2018-08-28 13:19:36 · 440 阅读 · 0 评论 -
Sudoku POJ - 3074(DFS)
Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the cells are written decimal digits from 1 to 9. The othe...原创 2018-05-10 21:14:30 · 367 阅读 · 0 评论 -
Addition Chains POJ - 2248(加深迭代搜索)
An addition chain for n is an integer sequence with the following four properties: a0 = 1 am = n a0 < a1 < a2 < … < am-1 < am For each k (1<=k<=m) there exist two (not nec...原创 2018-04-05 15:34:13 · 263 阅读 · 0 评论 -
Sticks POJ - 1011(枚举+dfs)
George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had orig...原创 2018-03-20 17:30:17 · 290 阅读 · 0 评论 -
(pat)A1103. Integer Factorization
The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K-P factorization of N for any positive...原创 2018-03-13 16:50:09 · 335 阅读 · 0 评论 -
(pat)A1013. Battle Over Cities
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we nee...原创 2018-03-09 11:57:27 · 236 阅读 · 0 评论 -
Travel HDU - 4284(dfs或状压dp)
PP loves travel. Her dream is to travel around country A which consists of N cities and M roads connecting them. PP has measured the money each road costs. But she still has one more problem: she doesn原创 2017-11-05 20:45:01 · 346 阅读 · 0 评论 -
Digital Square HDU - 4394 (数论)(DFS)
Given an integer N,you should come up with the minimum nonnegative integer M.M meets the follow condition: M2mod10x=nM^2 mod 10^x=n(x=0,1,2,3….) Input The first line has an integer T( T< = 1000), th原创 2017-10-16 00:18:10 · 339 阅读 · 0 评论 -
Pocket Cube HDU - 4801 (dfs)
Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes. For a combination of 2 × 2 mini-cubes which sharing a whole cube face, you can twist it 9原创 2017-09-29 15:15:00 · 355 阅读 · 0 评论 -
Connections between cities HDU - 2874(LCA)(RMQ)(dfs)(st算法)
After World War X, a lot of cities have been seriously damaged, and we need to rebuild those cities. However, some materials needed can only be produced in certain places. So we need to transport these原创 2017-09-15 16:38:59 · 356 阅读 · 0 评论 -
DeBruijin HDU - 2894 (df或欧拉回路)
旋转鼓的表面分成m块扇形,如图所示(m=8)。图中阴影区表示用导电材料制成,空白区用绝缘材料制成,终端a、b和c是3(k=3)处接地或不是接地分别用二进制信号0或1表示。因此,鼓的位置可用二进制信号表示。试问应如何选取这8个扇形的材料使每转过一个扇形都得到一个不同的二进制信号,即每转一周,能得到000到111的8个数。 那我们现在把旋转鼓的表面分成m块扇形,每一份记为0或1,使得任何相继的k个数的有原创 2017-08-18 15:49:22 · 473 阅读 · 0 评论 -
Genghis Khan the Conqueror HDU - 4126(MST)
Genghis Khan(成吉思汗)(1162-1227), also known by his birth name Temujin(铁木真) and temple name Taizu(元太祖), was the founder of the Mongol Empire and the greatest conqueror in Chinese history. After uniting ma原创 2017-07-22 11:48:11 · 418 阅读 · 0 评论 -
More Divisors ZOJ - 2562 (反素数)
Everybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is often not very conve原创 2017-07-29 14:03:37 · 412 阅读 · 0 评论 -
哈密顿绕行世界问题 (HDU - 2181 )(DFS)
一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 Input 前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出. Output 输出从第m个城市出发经过每个城市1次又回到m的所有路线,如有多条路线,按字典序输出,每行1条路线.每行首先输出是第几条路原创 2017-04-22 11:49:19 · 315 阅读 · 0 评论 -
网络寻路(深搜)
问题描述 X 国的一个网络使用若干条线路连接若干个节点。节点间的通信是双向的。某重要数据包,为了安全起见,必须恰好被转发两次到达目的地。该包可能在任意一个节点产生,我们需要知道该网络中一共有多少种不同的转发路径。源地址和目标地址可以相同,但中间节点必须不同。如下图所示的网络。1 -> 2 -> 3 -> 1 是允许的1 -> 2 -> 1 -> 2 或者 1 -> 2 -> 3 -> 2 都是非法原创 2017-04-05 14:53:12 · 614 阅读 · 0 评论 -
【51nod】最大公约数之和(简单数论或者积性)
给出一个n,求1-n这n个数,同n的最大公约数的和。比如:n = 6 1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15 Input 1个数N(N &amp;lt;= 10^9) Output 公约数之和 Input示例 6 Output示例 15 思路:先转化成数学公式: ans=∑i=1ngcd(i,n)ans=∑i=1ngcd(i,n)an...原创 2018-08-28 15:28:16 · 775 阅读 · 0 评论