很容易想到用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
题目链接:https://leetcode-cn.com/problems/number-of-islands/ 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量。一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的。你可以假设网格的四个边均被水包围。 示例 ...
分类:
其他好文 时间:
2020-03-13 01:33:06
阅读次数:
50
题目: 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
1. Sample Input 9 5 2 1 5 2 1 5 2 1 4 1 2 3 4 0 Sample Output 6 5 #include <bits/stdc++.h> using namespace std; typedef long long ll; int a[100]; bool ...
分类:
其他好文 时间:
2020-03-12 23:29:21
阅读次数:
69
#include #include #include using namespace std; const int MAXN = 10; bool isUsed[MAXN]; vector ans; int N; void DFS(int index) { if (index >= N) { //边... ...
分类:
其他好文 时间:
2020-03-12 23:15:39
阅读次数:
81
1. Sample Input 6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .# ...
分类:
其他好文 时间:
2020-03-12 09:53:53
阅读次数:
49