摘要:
A 思路: 直接遍历字符串s,判断是否依次出现过dfs和DFS 时间复杂度: O(∑n) #include <bits/stdc++.h> using namespace std; int t,n; string a; int main() { cin>>t; while(t--) { int s1 阅读全文
摘要:
AcWing-900 思路: 转换成完全背包问题 时间复杂度: o(n^3) AC代码: #include <iostream> #include <algorithm> using namespace std; const int N=1010,mod=1e9+7; int n; int f[N] 阅读全文
摘要:
p2758-编辑距离 思路: 用f[i][j]表示第一个字符串的前 i 个字母变为第二个字符串的前 j 个字母所用的最少操作次数。 假设第一个字符串为:AGTCTGACGC 第二个字符串为:AGTAAGTAGGC f[3][5] 表示把第一个字符串的前三个字母变为第二个字符串的前五个字母所需要的最少 阅读全文
摘要:
适用于多源汇求最短路的问题 原理: 基于动态规划 AcWing-854 AC code: #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N=510,INF=1e9; 阅读全文
摘要:
作用: 阅读全文
摘要:
A 时间复杂度: O(n) AC代码: #include <iostream> using namespace std; int n,cnt; int a[110]; bool is_isprime(int x) { if(x<2) return false; for(int i=2;i<=x/i; 阅读全文
摘要:
A 思路: 分解质因数当指数为1并且cnt==3时满足条件 时间复杂度: o(n) AC代码: #include <iostream> using namespace std; int l,r,cnt; bool k; int c[100]; void divide(int n) { int t=n 阅读全文
摘要:
A 思路: 签到题 AC代码: #include <bits/stdc++.h> using namespace std; int a,b,k; int main() { cin>>a>>b>>k; if(a>=k*b) cout<<"good"<<endl; else cout<<"bad"<<e 阅读全文
摘要:
一.存储 树是特殊的图 无向图是特殊的有向图 所以只需考虑有向图如何存储即可 1.邻接矩阵 空间复杂度o(n^2)-用的不多 2.邻接表(每一个节点都开一个单链表-存这个点可以走到哪个点) 注:内部点顺序无关紧要 二.遍历 (1)深度优先遍历DFS AcWing-846 #include <iost 阅读全文