Hungry3

梦想到达塔顶的蜗牛

2013年11月10日

ac自动机模板 知道的勿喷=.=

摘要: #include#includeusing namespace std;const int max_node=101;const int son_num=26;const int modn=2009;class ACAutomaton{ private: //每个节点的儿子,即当前节点的状态转移 int trie[max_node][son_num]; //记录题目给的关键数据 int val[max_node]; //fail指针 int fail[max_node]; //队列,用于广搜计算fail指针 int Q[max_node];... 阅读全文

posted @ 2013-11-10 20:53 Hungry3 阅读(172) 评论(0) 推荐(0)

Codeforces Round #208 (Div. 2) D. Dima and Hares DP

摘要: #include#includeusing namespace std;#define maxn 3100int a[maxn],b[maxn],c[maxn];int dp[maxn][2];int main(){ int i,j,n; cin>>n; for(i=1;i>a[i]; for(i=1;i>b[i]; for(i=1;i>c[i]; dp[n][0]=a[n]; dp[n][1]=b[n]; for(i=n-1;i>=1;i--) {//dp[i][0]第i只兔比第i-1只先喂,dp[i][1]第i只兔比第i-1只兔后喂 ... 阅读全文

posted @ 2013-11-10 18:12 Hungry3 阅读(196) 评论(0) 推荐(0)

kmp

摘要: void getnext(char *s){ i=0; j=-1; next[0]=-1; n=strlen(p); while(i<n) { if(j==-1||s[i]==s[j]) { i++,j++; next[i]=j; } else j=next[j]; }}void kmp(char *s,char *p){ i=j=0; n=strlen(s); m=strlen(p); while(i<n) { ... 阅读全文

posted @ 2013-11-10 16:38 Hungry3 阅读(191) 评论(0) 推荐(0)

hdu 4778 DP+博弈

摘要: 我们用dfs(state)来表示state状态时,先手-后手的最优值我们先来看一个简单模型:假设获得分数后“没有”再来一次的机会,那么A和B肯定是轮流取则结果就是dp[state]=max(取i的价值-dp[state^(1#include#includeusing namespace std;#define oo (1<<28)struct CNT{ int col[10];};CNT cnt[22];int dp[1<<22];int B,G,S;int dfs(int state,int *b1){ int b2[10]; int ans,res; int i,j 阅读全文

posted @ 2013-11-10 15:11 Hungry3 阅读(274) 评论(0) 推荐(0)

zoj 3686 线段树 先topo一次给所以结点编号就行了

摘要: #include#includeusing namespace std;#define pb push_back#define maxn 100000+100#define lson l,m,rt G[maxn];int id;void dfs(int u){ int i,j,v; L[u]=++id; for(i=0;i<G[u].size();i++) { v=G[u][i]; dfs(v); } R[u]=id;}void build(int l,int r,int rt){ sum[rt]=0; col[rt]... 阅读全文

posted @ 2013-11-10 14:43 Hungry3 阅读(168) 评论(0) 推荐(0)

2013年11月9日

字典树 为学自动机作准备

摘要: 简单分析原理:当树为空时,sz=1,我们去插入“abd”,此时u=0,c='a'-'a'=0,trie[u=0][c=0]=0,因此在u=0结点插入c=0这个子结点,trie[u=0][c=0]=sz++ =1;sz=2;然后往下个结点走u=trie[u=0][c=0]=1,c=‘b’-‘a’=1;此时发现trie[u=1][c=1]=0,因此我们又要新建子结点trie[u=1][c=1]=sz++ =2,sz=3;往下走u=trie[u=1][c=1]=2,c='d'-'a'=3,此时又发现trie[u=2][c=3]=0,又要 阅读全文

posted @ 2013-11-09 20:44 Hungry3 阅读(143) 评论(0) 推荐(0)

2013年11月8日

hdu 3415 单调队列 先求[1,i]的和,然后循环的,延迟一倍处理一下,令sum单调

摘要: #include#includeusing namespace std;#define inf (1>t; while(t--) { scanf("%d%d",&n,&k); sum[0]=0; for(i=1;isum[i-1]) tail--; p[++tail]=i-1; if(i-p[head]>k)head++; if(sum[i]-sum[p[head]]>ans) { ans=sum[i]... 阅读全文

posted @ 2013-11-08 23:25 Hungry3 阅读(138) 评论(0) 推荐(0)

导航