
dfs
_WAWA鱼_
郑州大学退役ACMer,目前在小米做浏览器内核(WebKit)开发,曾在科大讯飞实习做大模型SDK,努力成长中,欢迎大家一起学习和交流~
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
AtCoder Beginner Contest 236---D - Dance----dfs
#include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int N = 20; typedef pair<int,int> PII; vector<PII>vec; int w[N][N]; bool st[N]; int n; int dfs(int u) { if(u==n).原创 2022-01-24 10:08:09 · 382 阅读 · 0 评论 -
E、变异蛮牛----二分图+思维
E、变异蛮牛 二分图染色的方式dfs一下,求出黑点数量 从中任意选出两个黑点即为答案数量res*(res+1)/2 #include<iostream> #include<vector> using namespace std; const int N = 200010; #define int long long vector<int>e[N]; int n; int res=0; void dfs(int u,int fa,int f) { if(f)re原创 2022-01-21 22:53:26 · 160 阅读 · 0 评论 -
树的三个经典问题----树的重心、中心、最长路径
1.树的最长路径 权值为非负时 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 10010; int n; int h[N],e[N*2],w[N*2],ne[N*2],idx; int dist[N]; void add(int a,int b,int c){ e[id原创 2022-01-20 11:35:28 · 429 阅读 · 0 评论 -
[HAOI2016]食物链----记忆化搜索+dp思想
题目链接 #include <iostream> #include <cstring> #include <queue> #include <algorithm> using namespace std; const int N = 200010; int n, m; int cnt[N],din[N]; int e[N],ne[N],h[N],idx=0; void add(int a,int b) { e[idx]=b,ne[idx]=h[a]原创 2022-01-17 14:48:18 · 291 阅读 · 0 评论 -
回转游戏----IDA*+打表处理
题目链接 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 */ #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 100; int q[N];原创 2022-01-11 21:14:27 · 1909 阅读 · 0 评论 -
排书----IDA*+区间处理
题目链接 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 20; int q[N],w[5][N]; int n; int f() { int cnt=0; for(int i=0;i+1<n;i++) if(q[i+1]!=q[i]+1) cnt++;原创 2022-01-11 21:12:10 · 167 阅读 · 0 评论 -
送礼物----双向深搜+二分
题目链接 #include <iostream> #include <cstring> #include <algorithm> using namespace std; #define int long long const int N = 50; int we[1<<25],idx=0; int n,m,res=0,k=0; int w[N]; void dfs1(int u,int s) { if(u>=k) {原创 2022-01-11 17:12:41 · 159 阅读 · 0 评论 -
生日蛋糕---dfs+数学剪枝
题目链接 题解: https://www.acwing.com/solution/content/31876/ #include <iostream> #include <cstring> #include <algorithm> #include<cmath> using namespace std; const int N = 25,INF=0x3f3f3f3f; int n,m; int minv[N],mins[N]; int R[N],H[N];原创 2022-01-11 16:02:37 · 233 阅读 · 0 评论 -
小木棍----dfs+剪枝优化
题目链接 剪枝优化: 1.搜索顺序优化 2.排除等效冗余 3.一眼就看出来的优化 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 70; bool st[N]; int a[N],n; int sum=0,length=0; bool dfs(int u,int len,int start) { if(u*length=原创 2022-01-10 22:02:02 · 415 阅读 · 0 评论 -
分成互质组----简单dfs
题目链接 写法一: #include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int N = 15; int n; int p[N]; vector<int> g[N]; int res=20; bool st[N]; int gcd(int a,int b) { return b?gcd原创 2022-01-10 16:25:14 · 218 阅读 · 0 评论 -
[NOIP2000]单词接龙----简单dfs
题目链接 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 25; int g[N][N]; string words[N]; int used[N]; int n,res=0; char start; void dfs(string s,int u) { res=max(res,(int)s.size());原创 2022-01-10 15:07:38 · 734 阅读 · 0 评论 -
字串变换----双向广搜
字串变换 题目链接 #include <iostream> #include <cstring> #include <algorithm> #include <unordered_map> #include <queue> using namespace std; const int N = 6; string a[N],b[N]; string A,B; int idx=0; int extend(queue<string>&a原创 2022-01-09 21:12:19 · 448 阅读 · 0 评论 -
送外卖----dfs
题目链接 #include <iostream> #include <cstring> #include <algorithm> #include <unordered_map> using namespace std; const int N = 100010; int st[N]; bool f=false; int a[N],b[N]; char s[N]; int n; bool dfs(int u,int idx) { if(u<原创 2022-01-09 14:56:10 · 145 阅读 · 0 评论 -
八数码输出转换路径---bfs
#include <iostream> #include <cstring> #include <algorithm> #include <queue> #include <unordered_map> using namespace std; unordered_map<string,int>d; unordered_map<string,pair<string,char>>path; queue<...原创 2022-01-08 19:37:40 · 363 阅读 · 2 评论 -
拦截导弹+导弹防御系统-----二分+dfs迭代加深+贪心,原型为LIS
今天想了一下午+一晚上二分,终于想明白了,深深的被二分疑惑到了,所以lower_bound和upper_bound等等能手写的全手写了,哈哈哈哈哈。 1.拦截导弹 题目链接 这里是非dp写法,用的贪心写法,比较巧妙 手写了俩lower_bound和upper_bound函数 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1010;原创 2021-11-07 22:41:23 · 172 阅读 · 0 评论 -
PTA7-4 病毒溯源 (25 分)-----树的最大深度和字典序最小路径
#include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int N=10010; vector<int>v[N]; bool din[N]; int son[N]; int n; int dfs(int u) { int maxv=0; son[u]=-1; for(i..原创 2021-11-06 15:02:25 · 1450 阅读 · 0 评论 -
leetcode 394. 字符串解码
leetcode 394 字符串解码 题目链接 class Solution { public: string decodeString(string s) { vector<int>nums; string res; for(int i=0;i<s.size();i++) { if(!isdigit(s[i])) { res+=s[i];原创 2021-10-17 10:04:01 · 126 阅读 · 0 评论 -
补一补ZZU曾经的招新赛
E. Kirito and Asuna 描述 kirito为了纪念和Asuna认识的第100天,决定约Asuna出去玩,约会当然要买花了,Kirito不知道Asuna喜欢什么花,但是他知道Asuna有一个爱好,如果两种花的价格是互质的,那么Asuna就会喜欢这些花;如果超过两种的话,那么任意两种花的价格都要互质(若a和b的最大公因数是1,我们认为a和b互质)。Krito当然想买更多种花送给Asuna了,也想让Asuna喜欢他买的这些花,那么他最多能送给Asuna多少种花呢。 输入 第一行为一个数字n,1&l原创 2021-10-16 14:28:06 · 187 阅读 · 0 评论 -
leetcode 437. 路径总和 III
leetcode 437. 路径总和 III 题目链接 暴力双搜 复杂度 O(n^2) /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) :原创 2021-10-12 15:53:10 · 179 阅读 · 1 评论