![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
深度优先搜索
龍木
若人生为棋,我愿为卒,漫漫征途,谁曾见我后退半步
展开
-
力扣训练——搜索
本篇参照大佬博客练习题顺序,代码都是自打的,有些可能不是最优解。1091. 二进制矩阵中的最短路径class Solution {public: struct node{ int x; int y; int s; }; int shortestPathBinaryMatrix(vector<vector<int>>& grid) { queue<node>q;原创 2021-01-31 14:51:46 · 344 阅读 · 1 评论 -
L - Oil Deposits
https://vjudge.net/contest/402204#problem/LThe 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 that divides the land into原创 2020-10-19 12:42:38 · 126 阅读 · 0 评论 -
C - 哈密顿绕行世界问题
https://vjudge.net/contest/402248#problem/C一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出.Output输出从第m个城市出发经过每个城市1次又回到m的所有路线,如有多条路线,按字典序输出,每行1条路线.每行首先输出是第几条路线.然后个一原创 2020-10-18 19:57:01 · 240 阅读 · 0 评论 -
D. Solve The Maze
链接:https://codeforces.ml/contest/1365/problem/DVivek has encountered a problem. He has a maze that can be represented as ann×mn×mgrid. Each of the grid cells may represent the following:Empty— '.' Wall— '#' Good person — 'G' Bad person— 'B'Th...原创 2020-07-09 19:43:53 · 213 阅读 · 0 评论 -
E. Tree Shuffling
链接:https://codeforces.ml/contest/1363/problem/EAshish has a tree consisting ofnnnodes numbered11tonnrooted at node11. Theii-th node in the tree has a costaiai, and binary digitbibiis written in it. He wants to have binary digitciciwritten in...原创 2020-06-01 16:19:17 · 232 阅读 · 0 评论 -
C. Game On Leaves
链接https://codeforces.ml/contest/1363/problem/CAyush and Ashish play a game on an unrooted tree consisting ofnnnodes numbered11tonn. Players make the following move in turns:Select any leaf node in the tree and remove it together with any edge whic...原创 2020-06-01 16:18:09 · 234 阅读 · 0 评论 -
D. Nastya and Scoreboard
链接:https://codeforces.ml/contest/1341/problem/CDenis, who managed to buy flowers and sweets (you will learn about this story in the next task), went to a meeting with Nastya to invite her to become ...原创 2020-04-24 07:58:33 · 282 阅读 · 0 评论 -
C 矩阵消除游戏
链接:https://ac.nowcoder.com/acm/contest/4090/C牛妹在玩一个名为矩阵消除的游戏,矩阵的大小是{n}n行{m}m列,第{i}i行第{j}j列的单元格的权值为a_{i,j}ai,j,牛妹可以进行{k}k个回合的游戏,在每个回合,牛妹可以选择一行或者选择一列,然后将这一行或者这一列的所有单元格中的权值变为{0}0,同时牛妹的分数会加上这一行或者这一列中的所...原创 2020-02-28 22:50:59 · 641 阅读 · 0 评论 -
C 交换游戏
链接:https://ac.nowcoder.com/acm/contest/4462/C一列上有12个孔,这12个孔中有些孔被遮挡住了。假定我们用 '-' 来表示没被遮挡住的孔,用 'o' 来表示被遮挡住的孔。如果相邻的三个孔有两个孔被遮挡,并且被遮挡的两个孔相邻,就是 '-oo' 和 'oo-'。对于这样的三个孔,我们可以将中间的孔的遮挡物移开,代价是将一端的遮挡物移到另一端没...原创 2020-02-23 13:34:33 · 17219 阅读 · 5 评论 -
B2. Books Exchange (hard version)
链接:https://codeforces.com/contest/1249/problem/B2The only difference between easy and hard versions is constraints.There arennkids, each of them is reading a unique book. At the end of any day, ...原创 2019-10-23 16:40:53 · 563 阅读 · 0 评论 -
[kuangbin带你飞]专题一 简单搜索 --A - 棋盘问题
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n...原创 2019-08-17 14:15:00 · 108 阅读 · 0 评论 -
问题 D: 【例题4】Addition Chains
来源http://poj.org/problem?id=2248An addition chain for n is an integer sequence<a0,a1,a2,…,am><a0,a1,a2,…,am>with the following four properties:a0= 1am=na0< a1< a2<…&...原创 2019-07-04 18:32:20 · 594 阅读 · 0 评论 -
问题 C: 【例题3】小木棍
题目链接:http://acm.ocrosoft.com/problem.php?cid=1693&pid=2题目描述乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50。现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度。给出每段小木棍的长度,编程帮他找出原始木棍的最小可能长度。输入输入文件共有二行。第一...原创 2019-07-04 14:50:21 · 3510 阅读 · 1 评论 -
问题 A: 【例题1】数的划分
http://acm.ocrosoft.com/problem.php?cid=1693&pid=0题目描述将整数n分成k份,且每份不能为空,任意两种划分方案不能相同(不考虑顺序)。例如:n=7,k=3,下面三种划分方案被认为是相同的。1 1 51 5 15 1 1问有多少种不同的分法。输入n,k (6<n<=200,2<=k<=6)...原创 2019-07-04 12:52:19 · 710 阅读 · 0 评论 -
问题 I: 八皇后
题目描述会下国际象棋的人都很清楚:皇后可以在横、竖、斜线上不限步数地吃掉其他棋子。如何将8个皇后放在棋盘上(有8 × 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题。对于某个满足要求的8皇后的摆放方法,定义一个皇后串a与之对应,即a=b1b2...b8a=b1b2...b8,其中bi为相应摆法中第i行皇后所处的列数。已经知道8皇后问题一共有92组解(即92个不同的皇后串)。给...原创 2019-05-09 23:17:36 · 287 阅读 · 0 评论