上一页 1 2 3 4 5 6 ··· 8 下一页

2013年11月7日

数位dp 模版

摘要: 1 int dfs(int i, int s, bool e) {2 if (i == -1) return s == target_s;3 if (!e && ~dp[i][s]) return dp[i][s];4 int res = 0;5 int u = e ? num[i] : 9;6 for (int d = first ? 1 : 0; d <= u; ++d)7 res += dfs(i-1, new_s(s, d), e&&d == u);8 return e ? res : dp[i][s] = res;9 }Vi... 阅读全文

posted @ 2013-11-07 20:04 KimKyeYu 阅读(349) 评论(0) 推荐(0) 编辑

2013年10月29日

EOJ 2239 Friends

摘要: http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=2239poj http://poj.org/problem?id=1805题目的大概意思就是一些人要投票去三个地方,要注意的是同一个人如果同时有两或以上个想去的地方,那他就会弃权,其他的只要按照题目给的逻辑就可以了 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #incl... 阅读全文

posted @ 2013-10-29 20:03 KimKyeYu 阅读(206) 评论(0) 推荐(0) 编辑

2013年9月11日

EOJ 2103 小强寻宝I

摘要: http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=2103树型dp + 分组背包。 dp[u][V]表示 对于以根为u的子树、剩余pow为V(看作容量)时能得到的最优解,那么: 对于u的某一个状态dp[u][k]: 其子树vi有 size( dp[vi][j] ) 个状态,但仅有一个状态可以转移给 dp[u][k] ,所以必须以子树为单位分组。关于分组背包,详细请看: http://blog.csdn.net/nywsp/article/details/7737158 1 #include 2 #include 3 #inclu... 阅读全文

posted @ 2013-09-11 21:26 KimKyeYu 阅读(250) 评论(0) 推荐(0) 编辑

2013年9月9日

【转】后缀树 解析

摘要: 写这篇文章,主要是因为最近有个课题设计,里面用的字符串匹配。学习后缀树之前,先了解一下Trie这个数据结构Trie是一种搜索树,可用于存储并查找字符串。Trie每一条边都对应一个字符。在Trie中查找字符串S时,只要按顺序枚举S的各个字符,从Trie的根节点开始选择相应的边走,如果枚举完的同时恰好走到Trie树的叶子节点,说明S存在于Trie中。如果未到达叶子节点,或者枚举中未发现相应的边,则S没有被包含在Trie中。后缀树就是一种压缩后的Trie树。比如 S:banana,对S建立后缀树。首先给出S的后缀们0:banana1:anana2:nana3:ana4:na5:a6:空为了更清楚的表 阅读全文

posted @ 2013-09-09 21:11 KimKyeYu 阅读(448) 评论(0) 推荐(0) 编辑

2013年9月7日

EOJ 2450 sunny的队列

摘要: http://acm.cs.ecnu.edu.cn/problem.php?problemid=2450用单调队列 queue[] 维护一个可能作为最大值的序列,由贪心策略,这个序列是单调减的。扫描到元素 a[i] 时, 这个序列满足:1.始终保持队首元素是[i-k+1, i-1]的最大值。 (即 如果队首不在当前区间[i-k+1, i]中,则出队)2.队中其余元素则是将来队首出队后可能的最大值。综上,该算法是 O(n)的, 比 线段树 要快呢。参考链接: http://wenku.baidu.com/view/4d23b4d128ea81c758f578ae.html 1 #includ.. 阅读全文

posted @ 2013-09-07 22:14 KimKyeYu 阅读(300) 评论(0) 推荐(0) 编辑

2013年9月5日

EOJ 2377 Sequence

摘要: http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=2377用一个单调递减栈来实现贪心的思路——先合并小的。单调栈则是用来保存那些较大的(暂不该合并的)元素。单调栈依然不会用。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 #include13 #include14 #include15 #include16 #define MAXN 1000 阅读全文

posted @ 2013-09-05 21:24 KimKyeYu 阅读(150) 评论(0) 推荐(0) 编辑

2013年8月9日

EOJ 1029 走道铺砖

摘要: http://acm.cs.ecnu.edu.cn/problem.php?problemid=1029poj 2411 http://poj.org/problem?id=2411这个题目类属于状态压缩DP,对于状态压缩DP,其实最简单的理解就是把状态用比特位的形式表示出来,我们会在下面用例子来说明。假如现在我们在铺砖 位置(i, j), 并且假设之前的位置已经铺设好的了,在这个位置,我们的选择:1. 不用铺砖了,可能在(i-1, j)的时刻已经被竖着铺上了,然后考虑的是(i, j+1)2. 横铺砖,将(i, j+1)也铺上了,然后考虑的是(i, j+2)3. 竖着铺砖,(将i,j)和(i+ 阅读全文

posted @ 2013-08-09 17:29 KimKyeYu 阅读(775) 评论(1) 推荐(0) 编辑

2013年7月29日

最小费用最大流——maxflow+SPFA

摘要: 最小费用最大流: 即在所有最大流中,要求得到最少费用。(每条边有两个参数:容量cap, 费用cost)。 解法:每次找到费用最小的增广路。(即以费用为权的最短路) 仅需将最大流中的 bfs 替换为SPFA(因为有负权)。代码如下: 1 #define MAXN 1005 2 #define MAXM 10005 3 #define INF 0x3f3f3f3f 4 using namespace std; 5 6 struct P{ 7 int u, v, cap, cost, next; //容量cap, 单位流量费用cost。 8 }e[MAXM*4];... 阅读全文

posted @ 2013-07-29 19:36 KimKyeYu 阅读(577) 评论(0) 推荐(0) 编辑

2013年7月27日

最大流 之 Edmond Karp 算法模版

摘要: 算法简介:(复杂度 最坏O(VE^2) ) 不断寻找(bfs) 源点s 和 汇点t 之间的增广路,不断更新s流出量的值 以及 这条路上的 残余网络值,直到找不到增广路。 此时,s流出量的值达到最大,故称之最大流。 增广路:(不同于二分匹配那个) 这条路从源点开始一直一段一段的连到了汇点,并且,这条路上的每一段都满足流量 q;13 memset(vis, 0, sizeof(vis));14 pre[s] = s;15 vis[s] = 1;16 q.push(s);17 while(!q.empty()){18 int p =... 阅读全文

posted @ 2013-07-27 17:16 KimKyeYu 阅读(256) 评论(0) 推荐(0) 编辑

2013年7月24日

hdu 4604 Deque

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4604想了半天,发现是LIS,O(nlgn)飘过。具体思路:预处理好以i为开头的(下面我用逆序输入,所以是以i为结尾的)LIS和LDS。 再枚举每个点找最优即可(注意不严格递增、减)。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #... 阅读全文

posted @ 2013-07-24 21:14 KimKyeYu 阅读(199) 评论(1) 推荐(0) 编辑

上一页 1 2 3 4 5 6 ··· 8 下一页

导航