代码仓库目录:01.【数学方法】矩阵快速幂02.【数学方法】高斯消元(naïve版)03.【数学方法】高斯消元(mid版)04.【字符串啊】Manacher算法(回文串)05.【字符串啊】KMP(字符串匹配)06.【数据结构】线段树(ZKW单点修改)07.【数据结构】线段树(RMQ)08.【数据结构】线段树(区间加+赋值)09.【数据结构】Splay树(未完全测试)////!!!!10.【数据结构】AVL树(平衡树)11.【图论图论】最小生成树(prim)12.【图论图论】次小生成树13.【图论图论】最大流(Dinic)14.【图论图论】LCA+最大生成树(truck)15.【动态规划】背包01,多重,完全矩阵模板#include
#include#includeusingnamespacestd;typedeflonglongll;constintP=9973;constintN=13;lln,m;structmatrix{lla[N][N];introw,col;matrix():row(N),col(N){memset(a,0,sizeof(a));}//???matrix(intx,inty):row(x),col(y){memset(a,0,sizeof(a));}ll*operator[](intx){returna[x];}matrixoperator*(matrixx){matrixtmp;for(inti=0;i<=n+1;i++)for(intj=0;j<=n+1;j++){tmp[i][j]=0;for(intk=0;k<=n+1;k++)tmp[i][j]=(tmp[i][j]+a[i][k]*x[k][j])%P;}returntmp;}voidoperator*=(matrixx){*this=*this*x;}matrixoperator^(llx){matrixret;for(inti=0;i<=n+1;i++)ret[i][i]=1;matrixtmp=*this;for(;x;x>>=1,tmp*=tmp){if(x&1)ret*=tmp;}returnret;}voidprint(){for(inti=0;i<=n+1;i++){for(intj=0;j<=n+1;j++)printf("%d",a[i][j]);puts("");}}};高斯消元,判断有无解的#include#include#include#include#includeusingnamespacestd;typedeflonglongLL;constdoubleEPS=1e-6;constintN=55;structmatrix{inta[N][N];introw,col;matrix():row(N),col(N){memset(a,0,sizeof(a));}matrix(intx,inty):row(x),col(y){memset(a,0,sizeof(a));}int*operator[](intx){returna[x];}voidprint(){for(inti=0;i#include#include#include#includeusingnamespacestd;constintN=1010;constdoubleEPS=1e-7;intm,n;doublea[N][N],x[N];intGauss(intm,intn){intcol=0,k=0;//col为列号,k为行号for(;kfabs(a[r][col]))r=i;if(fabs(a[r][col])EPS){doublet=a[i][col]/a[k][col];for(intj=col;j<=n;j++)a[i][j]-=a[k][j]*t;a[i][col]=0;}}for(inti=k;iEPS)return-1;if(k=0;i--){//回带求解doubletemp=a[i][n];for(intj=i+1;j#include#include#include#includeusingnamespacestd;constintN=233333;//20W//在o(n)时间内算出以每个点为中心的最大回文串长度intManacher(stringst){intlen=st.size();int*p=newint[len+1];memset(p,0,sizeof(p));intmx=0,id=0;for(inti=1;i<=len;i++){if(mx>i)p[i]=min(p[2*id-i],mx-i);elsep[i]=1;while(st[i+p[i]]==st[i-p[i]])p[i]++;if(i+p[i]>mx){mx=i+p[i];id=i;}}intma=0;for(inti=1;i