DFS使用c++中的stack,BFS使用c++中的queue 1 #include <iostream> 2 #define MAX_VERTS 20 3 #include <stack> 4 #include <queue> 5 6 using namespace std; 7 8 class ...
分类:
其他好文 时间:
2020-03-14 20:24:01
阅读次数:
68
//先输入行列,在输入迷宫 以-1 -1 结束 #include<stdio.h> #include<stdlib.h> #define MAXSIZE 100 #define ERROR -1 #define OK 1 struct Direction { int incX; //增量 int i ...
分类:
其他好文 时间:
2020-03-14 13:05:04
阅读次数:
69
Problem 给定n个正数,从中选出K个来使得他们的和为S,请问一共有多少种方法? Input: The first line, an integer T<=100, indicates the number of test cases. For each case, there are two ...
分类:
其他好文 时间:
2020-03-14 12:52:39
阅读次数:
49
八皇后代码 来自 https://www.bilibili.com/video/av21776496?from=search&seid=14795429927506117804 迷宫寻路自己写的 迷宫寻路(1 为障碍,2 为路) #define _CRT_SECURE_NO_WARNINGS #in ...
分类:
其他好文 时间:
2020-03-14 12:47:48
阅读次数:
51
很容易想到用DP或记忆化搜索解决。 状态转移方程: dp[i][j] = MAX(dp[i][j] , 1 + dp(neighbor) ) 注意dp[i][j] 先要全部置1 由于记忆化搜索的做法没什么特别的,就是一个dfs+标记数组,就不多写了。 如何DP?这道题显然不能常规的线性DP,因为子问 ...
分类:
其他好文 时间:
2020-03-14 11:19:09
阅读次数:
46
题:https://codeforces.com/contest/1324/problem/F 题意:给节点数为n的树,每个节点有0和1,对于每个节点输出他的ans,这个ans是砍掉一些子树后0节点的数目减去1节点的数目(得留下自己) 分析:我们按照统计子树的size一样,来dfs这个树,对于父亲u ...
分类:
其他好文 时间:
2020-03-14 00:48:43
阅读次数:
52
独立岛屿数 题目来源 "LeetCode 200. Number of Islands" 解题思路 暴力:遍历+dfs/bsf 查并集 精简解题 ...
分类:
其他好文 时间:
2020-03-13 14:39:12
阅读次数:
57
题意~~反向~~翻译: A tree with N points, with point 1 as the root, and the tree points have edge weights. Then there are M There are three types of operation ...
分类:
其他好文 时间:
2020-03-13 13:06:54
阅读次数:
55
题目: http://www.fjutacm.com/Contest.jsp?cid=860#P3 代码 一, #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<queue> #include< ...
分类:
其他好文 时间:
2020-03-13 01:06:57
阅读次数:
79
题意 给你无根一颗树,每个节点是黑色或白色。对于每一个节点,问包含该节点的权值最大的子树。 子树的权值等于子树中白点的个数减去黑点的个数。 注意,这里的子树指的是树的联通子图。 解题思路 这场就这题卡的比较久。 首先,如果是有根树的话,只需要dfs一遍就能得出根的答案。 设根为1,将无根树转为有根树 ...
分类:
其他好文 时间:
2020-03-13 01:05:27
阅读次数:
45