随笔分类 - dfs
摘要:输入样例: 6 2 1 3 2 4 3 5 2 6 1 输出样例: 4 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> PII; const LL N=100200,M=20
阅读全文
摘要:https://www.acwing.com/problem/content/1052/ 输入样例: 1 7 3 输出样例: 8 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,i
阅读全文
摘要:https://ac.nowcoder.com/acm/problem/16695 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII; const LL MAXN=
阅读全文
摘要:https://www.acwing.com/problem/content/description/131/ 输入样例: 3 输出样例: 123 132 213 231 321 #include<bits/stdc++.h> using namespace std; typedef long lo
阅读全文
摘要:https://www.acwing.com/problem/content/1493/ 输入样例1: 4 1 1 2 输出样例1: 2 输入样例2: 10 5 1 2 3 4 5 6 7 8 9 10 输出样例2: 112512 #include<bits/stdc++.h> using name
阅读全文
摘要:https://www.acwing.com/problem/content/1113/ #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII; const LL MA
阅读全文
摘要:https://codeforces.com/contest/1843/problem/D ``` 题目大意: 一颗树中,每次给定两个结点,每个结点都可以移动到孩子结点,最后可以到达叶子结点, 问我们这两个结点最终移到叶子结点有多少种组合? (其实就是让求以这两个节点为根的子树的叶子结点个数的乘积)
阅读全文
摘要:https://codeforces.com/contest/1144/problem/F 题目大意: 给定n个点,m条边; 每一条边都连接了两个点。 现在需要我们染色,要求是做到所有有向图不包含长度为2或者更长的路径。 input 6 5 1 5 2 1 1 4 3 1 6 1 output YE
阅读全文
摘要:https://www.acwing.com/activity/content/competition/problem_list/3088/ 果然绩点成绩和竞赛水平总得寄一个(to me ###4944. 热身计算 #include<bits/stdc++.h> using namespace st
阅读全文
摘要:https://www.acwing.com/problem/content/4871/ 题目大意: 给定两个整数 n,x。(x为原始数据,n为需要我们把x变成的位数) 可以对x进行任意次以下操作: 选择x的一位数字y,将x替换为x*y。 求出把x变成n位数的最小操作数,如果无法达到,输出-1. 扩
阅读全文
摘要:https://www.acwing.com/problem/content/167/ 一共N只小猫,每个缆车最大承重量为W。N只小猫的重量分别是 C1、C2……CN。 当然,每辆缆车上的小猫的重量之和不能超过 W。 每租用一辆缆车,翰翰和达达就要付1美元,所以他们想知道,最少需要付多少美元才能把这
阅读全文
摘要:半个多月没写题,连暴力dfs都忘记了,完蛋,烂菜地里了 https://atcoder.jp/contests/abc289/tasks/abc289_c 题目大意: 给定一个N,M个集合,然后分别给出M个集合里面的数字个数以及每个数, 问我们怎样选集合能达到1到N的每一个数字都存在,问我们这样的选
阅读全文
摘要:https://ac.nowcoder.com/acm/contest/49244/D 每个点的价值是它到根节点的路径上所有节点的所有点权和(包括它自己) 点数其实也就是从根节点数 这棵子树有多少个子节点,这就是出现次数 显而易见所有点的权值都可以随便变化,没有规定变换次数,所以我们可以随意变换成我
阅读全文
摘要:https://atcoder.jp/contests/dp/tasks/dp_g 题目大意: 给定n个点,m条有向边(确定无环),问最长路径是多少? Sample Input 1 4 5 1 2 1 3 3 2 2 4 3 4 Sample Output 1 3 #include<bits/std
阅读全文
摘要:A - Rightmost #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> PII; const LL MAXN=1e18; const LL INF=1e9; const
阅读全文
摘要:D. Masha and a Beautiful Tree 题目大意: 给定一颗满二叉树的叶子节点,让我们更换子树位置,从而让叶子节点排序为升序 求最小操作数,如果不能移动成那样的话,直接输出-1. input 4 8 6 5 7 8 4 3 1 2 4 3 1 4 2 1 1 8 7 8 4 3
阅读全文
摘要:https://atcoder.jp/contests/abc274/tasks A - Batting Average #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> PI
阅读全文
摘要:https://www.luogu.com.cn/problem/P3183 题目大意: 给定n个节点,标号分别为1——n,然后给出m条有向边,问我们不同的食物链路径有多少? 输入 #1 10 16 1 2 1 4 1 10 2 3 2 5 4 3 4 5 4 8 6 5 7 6 7 9 8 5 9
阅读全文
摘要:https://www.luogu.com.cn/problem/P1434 题目大意: 找一条路径,从高到低,遍历过的地点最长。 输入 #1 5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 输出 #1 25
阅读全文
摘要:https://www.luogu.com.cn/problem/P1464 单个返回条件的时候,直接return 多个返回条件的时候,采用记忆化搜索思想,边存储边继续往下搜索 中间穿插记忆化判断,如果之前有过此类记录,直接拿来用,没有的话就继续往下搜索 #include<bits/stdc++.h
阅读全文