上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 25 下一页
摘要: 求区间内最长连续上升子序列线段树典型区间合并 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 #define lson l, m, rt << 1 7 #define rson m + 1, r, rt << 1 | 1 8 9 using namespace std; 10 11 const int MAXN = 100010; 12 13 int N, Q; 14 int Lval[ MAX 阅读全文
posted @ 2013-05-09 00:35 冰鸮 阅读(164) 评论(0) 推荐(0)
摘要: 原文转自:http://jijiwaiwai163.blog.163.com/blog/static/1862962112012623105531177/1、KMP算法 KMP算法是一种改进后的字符串匹配算法,由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。通过一个辅助函数实现跳过扫描不必要的目标串字符,以达到优化效果。 KMP(O(n+m))算法与传统的BF算法(O(n*m))想比自然快了许多。 KMP(Knuth-Morris-Pratt)算法核心思想是:在发生失配时,主串不需要回溯,而是利用已经得.. 阅读全文
posted @ 2013-05-08 23:42 冰鸮 阅读(190) 评论(0) 推荐(0)
摘要: 树状数组+扫描线官方题解:本题题目大意在一个01方阵中找出四条边全都是1的正方形的个数,对于正方形内部则没有要求。 一个直观的想法是首先用N^2的时间预处理出每一个是1的点向上下左右四个方向能够延伸的1的最大长度,记为四个数组l, r, u, d。然后我们观察到正方形有一个特征是同一对角线上的两个顶点在原方阵的同一条对角线上。于是我们可以想到枚举原来方阵的每条对角线,然后我们对于每条对角线枚举对角线上所有是1的点i,那么我们可以发现可能和i构成正方形的点应该在该对角线的 [i, i + min(r[i], d[i]) – 1] 闭区间内, 而在这个区间内的点 j 只要满足 j – i + 1 阅读全文
posted @ 2013-05-08 23:36 冰鸮 阅读(189) 评论(0) 推荐(0)
摘要: 线段树 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 #define lson l, m, rt << 1 7 #define rson m + 1, r, rt << 1 | 1 8 9 using namespace std; 10 11 const int MAXN = 1000010; 12 13 char str1[MAXN]; 14 char str2[MAXN]; 15 bool 阅读全文
posted @ 2013-05-06 22:43 冰鸮 阅读(276) 评论(0) 推荐(0)
摘要: 线段树 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 #define lson l, m, rt << 1 7 #define rson m + 1, r, rt << 1 | 1 8 9 using namespace std; 10 11 const int MAXN = 100010; 12 13 int N, Q; 14 int color[ MAXN << 2 ]; // 阅读全文
posted @ 2013-05-06 22:39 冰鸮 阅读(238) 评论(0) 推荐(0)
摘要: dp[k][i][j]表示第k步左脚在位置 i,右脚在位置 j 状态时的最小能量消耗.dp[k][i][j] = min( dp[ k - 1 ][x][j] + cost[x][ step[k] ], dp[ k - 1 ][i][x] + cost[x][ step[k] ] );这题很坑爹的没有数据范围,数组我随便开的,居然1Y了…… 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 using namespace 阅读全文
posted @ 2013-05-05 22:08 冰鸮 阅读(208) 评论(0) 推荐(0)
摘要: 区间DP,刘汝佳黑书p113例题 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 6 using namespace std; 7 8 const int MAXN = 210; 9 const int INF = 1 << 30;10 11 char str[MAXN];12 int dp[MAXN][MAXN];13 int path[MAXN][MAXN];14 bool vis[MAXN][MAXN]; 阅读全文
posted @ 2013-05-05 20:07 冰鸮 阅读(204) 评论(0) 推荐(0)
摘要: 题意:给你一棵树,求树中某节点子树中能力值大于它且忠诚度最高的那个。在第一次看到这个问题是,我有一个疑问:解决这个问题有两个关键点:1.树形结构到线性结构的转换原因:员工关系整棵树是一棵结构不确定的树,员工编号不一定连续,对于查询其符合条件的下属有很大困难(只能暴力)。而编号之后可以将子树映射到编号连续的一段区间,这时就可以用线段树快速查询最值。做法:用邻接表保存树,从根开始DFS,记录每棵子树的起始端点和终止端点。2.对能力值从大到小进行排序,按能力值从大到小的顺序加入线段树,能力值相同时,编号小的在前面。原因:因为每次要查找能力值大于该人且忠诚度最高的那个下属,所以当该点插入线段树时,线段 阅读全文
posted @ 2013-05-05 15:59 冰鸮 阅读(355) 评论(0) 推荐(0)
摘要: S表示已用骰子的集合。dp[S][i][j]表示在当前集合下,最上面那个骰子为 i ,底面编号为 j 时所能得到的最大和, max[i][j] 表示骰子 i 以 j 为底时侧面的最大值,dice[i][j]表示 i 骰子 j 面的编号。dp[S][i][j] = max{ dp[ S ^ ( 1 << i ) ][k][m]+max[i][j] };k∈(S ^ ( 1 << i ) ), dice[k][5 - m]==dice[i][j]。为了方便判断相对的面,存储时处理一下,使得相对的面存储在编号加和为5的位置中。即如果 a, b 面相对,则 a + b = 5 阅读全文
posted @ 2013-05-04 22:19 冰鸮 阅读(188) 评论(0) 推荐(0)
摘要: 有两种做法:一种是经典二分图最小顶点覆盖,一种是树形DP,我用的后者。第一次学习树形DP…… 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <vector> 5 #include <algorithm> 6 7 using namespace std; 8 9 const int MAXN = 1600;10 11 int N, root;12 int dp[MAXN][2];13 vector<int> tree[MAXN 阅读全文
posted @ 2013-05-04 08:59 冰鸮 阅读(320) 评论(2) 推荐(0)
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 25 下一页