摘要:
阅读全文
摘要:
AC代码如下: #include <bits/stdc++.h> using namespace std; bool judge(string s, int pos){ swap(s[pos], s[pos + 1]); swap(s[s.length() - pos - 1],s[s.length 阅读全文
摘要:
#include <iostream> using namespace std; int n ; const int N = 1e6 + 5; int a[N]; void quick_sort(int a[], int l , int r ){ if(l >= r) return; int i = 阅读全文
摘要:
题目: 地址:https://www.acwing.com/problem/content/104/ 这道题的二分性体现在平均值的最优性中 假设最大值为MAX,我们当前要判断的值为MID 当MID > MAX时,我们在当前条件下一定找不到符合假设的解,从而判断出比MID大的值全部无效。 当MID < 阅读全文
摘要:
题目: 代码 #include <iostream> using namespace std; int sta[105]; int n, top = 0; void dfs(int sum, int lst) { if (sum > n) { return ; } if (sum == n) { f 阅读全文
摘要:
题目:https://www.luogu.com.cn/problem/P1216 //还需理解 #include <iostream> #include <algorithm> #include <cstring> using namespace std; int r; int num[1005] 阅读全文
摘要:
1.什么情况下可以使用动态规划来解决问题: (1)往往在求最优解的问题中使用动态规划。 (2)一个大问题可以被分解为小问题,且每一个子问题都对应一个互不相同的状态。 (3)在问题状态每次发生改变时,需要进行判断来决定如何改变。 阅读全文
摘要:
1.使用递归 时间复杂度为O(n) #include <iostream> int F[105];//储存之前的数据 int fib(int n) { if(n<=2) return F[n]=1; if( F[n] ) return F[n]; //使用记忆化搜索来降低实践复杂度 return F 阅读全文
摘要:
快速幂模板: int qmi(int m, int k, int p){ int res = 1 % p, m; while (k) { if (k&1) res = res * m % p;m = m * m % p; k >>= 1; } return res;} 时间复杂度为O(logk). 阅读全文