- 博客(11)
- 收藏
- 关注
原创 边数受限的最短路(状态压缩DP)
#include#include#includeusing namespace std;const int maxn=1<<10;const int maxm=31;const int INF=1<<29;int t[maxm];int d[maxm][maxm];double dp[maxn][maxm];void solve(){for(int i=0;i<(1<<n);i++)fill(da[i],dp[i]+m+1,INF);dp
2021-01-10 14:53:05
84
原创 剪苹果枝(树上DP)
#include#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;const int ee=105;int n,q;int tree[ee][5]={0},ma[ee][ee]={0},num[ee]={0},f[ee][ee]={0};void preprocess(){for(int i=0;i<=
2021-01-10 12:29:14
96
原创 AC自动机
#include#include#includeusing namespace std;const int maxnode=11000;const int sigma_size=26;struct AC_Automata{int ch[maxnode][sigma_size];int val[maxnode];int f[maxnode];int l[maxnode];int sz;void init(){sz=1;memset(ch[0],0,sizeof(ch[0]));
2021-01-08 21:32:59
67
原创 KMP
#include#include#include#includeusing namespace std;#define MAXN 1010int ans;char text[MAXN],pattern[MAXN];int next[MAXN];void getNext(){int m=strlen(pattern);next[0]=next[1]=0;for(int i=1;i<m;i++){int j=next[i];while(j&&pattern[j]
2021-01-08 16:50:25
54
原创 求最大异或数(Tire树)
#include #include #include #difine maxn 10000+5using namespace std;typedef long long LL;ina a[maxn],n,m;int ch[32maxn][2];LL val[32maxn];int code_cnt;void inti(){node_cnt=1;memset(ch[0],0,sizeof(ch[0]));}void Insert(LL x){int u=0;for(int i=
2021-01-08 15:56:06
123
原创 Tire树
const int maxnode=4000100+10;const int sigma_size=26;stuct Tire{int ch[maxnode][sigma_size];int val[maxnode];int sz;}void clear(){sz=1;mamset(ch[0],0,sizeof(ch[0]));}int idx(char c){return c-‘a’;}void insert(const chars,int v){int u=0,n=strlen(s)
2021-01-08 13:14:51
60
原创 求波动值(SPLAY树实现)
#include #include using namespace std;const int inf=0x7fffffff;struct splay_tree{unsigned long p_size;struct node{node l,r,p;int key;node(int key):l(NULL),r(NULL),p(NULL),key(key){}~node(){if(l)delete l;if®delete r;if§delete p;}}root;void r
2021-01-05 18:02:33
265
原创 插入输出(TREAP)
#include <stdlib.h>#include struct Node{int size,key,weight;Node* l,* r;Node(int key):key(key){ size=1; weight=rand(); l=r=NULL;}};int get_size(Nodenode){return node==NULL?0:node->size;}void left_rotate(Node&a){Node* b=a->r;
2021-01-04 21:12:18
60
原创 已知A求单增B使得∑|Ai-Bi|最小(左倾堆实现)
1.左倾堆的节点的键值小于等于子节点的键值(堆性质)2.左孩子的NPL大于等于右孩子的NPL(左倾性质)3.NPLF=NPLRC+14.左倾堆的子树为左倾堆#include #include #include #include using namespace std;const int N=50005;int a[N],root[N],num[N];struct LHeap{int l,r,key,dis,sz;bool operator<(const LHeap lh)co
2021-01-04 17:48:14
346
原创 逆序数(树状数组实现)
#include #include using namespace std;const int N=1000;int lowbit(int x){return x&(-x);}void change(int *c,int position,int value,int len){while(position<=len){c[position]+=value;position+=lowbit(position);}}int sum(int *c,int n){int
2021-01-03 12:29:55
59
原创 堆排序
#include /* run this program using the console pauser or add your own getch, system(“pause”) or input loop /void heap_adjust(int a,int f,int n){int c=2f+1;int t=a[f];while(c<n){if(c+1<n&&a[c+1]>a[c])c++;if(a[f]>=a[c])break;a[f]
2021-01-02 12:53:01
53
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人