![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
template
honghuidan
这个作者很懒,什么都没留下…
展开
-
KMP相关算法
void GetNext(int P[], int next[]) { int p_len = m; int i = 0; int j = -1; next[0] = -1; while (i < p_len) { if (j == -1 || P[i] == P[j]) { i++; j++;原创 2017-08-15 14:12:00 · 146 阅读 · 0 评论 -
拓展欧几里得算法
通过拓展欧几里得算法,调用exgcd(a,b,x,y),可求得ax+by=1的一组解 int exgcd(int a,int b,int &x,int &y){ int d=a; if(b!=0){ d=exgcd(b,a%b,y,x); y-=(a/b)*x; } else{ x=1; y=0;原创 2017-08-14 15:27:56 · 229 阅读 · 0 评论 -
快速幂
NEUOJ 333 快速幂模板 快速幂用递归写会超时,必须得用while循环写 #include typedef long long LL; const LL p=1e9+7; LL a,b,c; LL pow(LL base,LL exp,LL MOD){ LL res=1; while(exp){ if(exp&1LL)res=res*base%MO原创 2017-08-09 13:32:04 · 171 阅读 · 0 评论 -
网络流
Ford-Fulkerson #include #include #include const int MAX_V=100+5; const int INF=0x3fffffff; struct edge{ int to,cap,rev; }; vector G[MAX_V]; bool used[MAX_V]; void add_edge(int from,int to,i原创 2017-08-11 22:11:12 · 148 阅读 · 0 评论 -
矩阵
矩阵乘法 矩阵快速幂原创 2017-08-09 19:05:42 · 137 阅读 · 0 评论 -
字典树
字典树原创 2017-08-16 20:03:48 · 178 阅读 · 0 评论 -
数位dp
数位dp大致有两种写法,第一种是通过递推关系,推出不同状态之间的数学关系,预处理出dp数组内的数据。但这对数学的要求很高,一般人很难驾驭。 第二种是通过记忆化搜索,程序直白易理解,适合大多数情况下使用。 数位dp也是有模板的,因为核心思想都是差不多的。 #include #include int dp[8][2];原创 2017-08-24 10:51:28 · 189 阅读 · 0 评论