上一页 1 ··· 4 5 6 7 8 9 下一页
摘要: 1.0/1分数规划模板 例题:poj2976 二分求解M,M即为答案 #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; stru 阅读全文
posted @ 2023-04-18 22:30 天雷小兔 阅读(63) 评论(0) 推荐(0)
摘要: 1.矩阵快速幂 struct matrix{ll mat[N][N];}a; matrix operator *(const matrix &a,const matrix &b){ matrix c; memset(c.mat,0,sizeof(c.mat)); for(int i=0;i<N;i+ 阅读全文
posted @ 2023-04-15 08:50 天雷小兔 阅读(41) 评论(0) 推荐(0)
摘要: 后缀自动机是通过一个DAG图来存储的,使空间更小,后缀自动机中最关键的一项技术叫做后缀链。 1.建立SAM void insert(int c){ newNode(t[last].len+1); int p=last,cur=sz; while(p!=-1&&!t[p].son[c])t[p].so 阅读全文
posted @ 2023-04-01 12:00 天雷小兔 阅读(32) 评论(0) 推荐(0)
摘要: KMP算法的要点是避免回溯和Next[]数组,其中,Next[]数组中存的是最长公共前后缀的长度. 1.KMP模板 例题:HDU2087剪花布条 int Next[N],cnt;//构建Next[]数组 void getNext(char *p,int plen){ Next[1]=Next[0]= 阅读全文
posted @ 2023-03-25 21:21 天雷小兔 阅读(28) 评论(0) 推荐(0)
摘要: 1.动态分配空间 const int N = 27; struct trie{ trie *Next[N]; int flag; trie(){ flag=1; memset(Next,NULL,sizeof(Next)); } }*root; void insert(string s){ int 阅读全文
posted @ 2023-03-22 20:56 天雷小兔 阅读(22) 评论(3) 推荐(0)
摘要: 1.STL离散化 void LiSH(){ cin>>n; for(int i=1;i<=n;i++)cin>>olda[i],newa[i]=olda[i]; sort(olda+1,olda+n+1); int cnt=unique(olda+1,olda+n+1)-( 2.离散化+线段树 例题 阅读全文
posted @ 2023-03-20 21:41 天雷小兔 阅读(31) 评论(0) 推荐(0)
摘要: 差分是前缀和的逆操作 差分可以再O(1)的时间里让区间[x,y]进行加减操作 求出差分数组即可求出操作后的数组 一维差分 例题:HDU1556 for(int i=1;i<=n;i++){ int L,R;cin>>L>>R; d[L]++;d[R+1]--; } for(int i=1;i<=n; 阅读全文
posted @ 2023-03-18 11:55 天雷小兔 阅读(23) 评论(0) 推荐(0)
摘要: 1.普通并查集 int fa[N],n,m,x,y; void init(){ for(int i=0;i<N;i++)fa[i]=i; } int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); } void merge(int x,int y) 阅读全文
posted @ 2023-03-02 11:06 天雷小兔 阅读(22) 评论(0) 推荐(0)
摘要: 1.循环枚举 for(int a=1;a<=3;a++){ for(int b=1;b<=3;b++){ for(int c=1;c<=3;c++){ for(int d=1;d<=3;d++){ for(int e=1;e<=3;e++){ for(int f=1;f<=3;f++){ for(i 阅读全文
posted @ 2023-03-02 09:46 天雷小兔 阅读(20) 评论(0) 推荐(0)
摘要: 1.深度优先搜索求连通块个数 void dfs(int x,int y){ vis[x][y]=1; for(int i=0;i<8;i++){ int h=x+dx[i],l=y+dy[i]; if(h<1||h>n||l<1||l>m||vis[h][l])continue; dfs(h,l); 阅读全文
posted @ 2023-03-01 22:20 天雷小兔 阅读(28) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 下一页