摘要: 题意:很简单,不废话了- -在这道题中单调队列的作用:在线性时间内维护定长区间的最值。单调队列没学过的话去学一下这题吧转移的时候dp[i][k]->dp[i+1][j],k与j的差距不超过T,分两种情况转移,k在j的左边和右边,所以维护T长度的最值,双向扫一遍就OK了 (从右边扫过来) k j j k<--------T-------> <--------T-------> dp[i+j][... 阅读全文
posted @ 2012-08-29 21:50 编程菜菜 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 题意: 给定每天的股票买进上限,买进价格,卖出上限,卖出价格,每两次买卖操作中间必须间隔w天,每天最多持有maxp个股票,问n天后最大收益是多少题解: DP方程显然: dp[i][j]=max(不买不卖,买入操作,卖出操作)不买不卖 dp[i][j]=max(dp[i][j],dp[i-1][j])买 dp[i][j]=max(dp[pre][k]-(j-k)*AP[i]) dp[i][j]+j*... 阅读全文
posted @ 2012-08-29 17:12 编程菜菜 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 很裸的一道单调队列题(把数列扩大一倍即可),但是要注意题目的比较条件(定义比较函数),不然会WA代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N=100010;typedef pair<int,int> PII;int T,n,... 阅读全文
posted @ 2012-08-28 23:22 编程菜菜 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 斜率优化DP入门题O(n^2)方程: dp[i]=dp[j]+M+(sum[i]-sum[j])^2;用斜率优化掉枚举j的O(n)代码(含输入输出外挂):#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int N=500010;typedef long long LL;#define... 阅读全文
posted @ 2012-08-28 23:16 编程菜菜 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 斜率优化DP:未优化方程:dp[i]=dp[j]+C+(a[i]-a[j+1])^2;解法同HDU3507Trick: 检查斜率时不能用叉乘 直接检查即可(不然数字范围过大超long long会WA)代码:#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <math.h>usin... 阅读全文
posted @ 2012-08-28 23:16 编程菜菜 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 第一道斜率优化DP题方法:参考论文《浅谈数形结合思想在信息学竞赛中的应用》 的例2 构造凸包 求切点代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N=100010;int n,k;int a[N],sum[N];int que[... 阅读全文
posted @ 2012-08-27 11:15 编程菜菜 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 操作:1. 将 a b 区间染上颜色z2. 统计a b区间内颜色为z的点的个数此题若用普通线段树会退化成O(n)比赛时YY了一个map<int,int>的线段树 HLL的MLE了赛后才知道可以YY剪枝过 方法:记录区间被染的最小颜色和最大颜色 若查询颜色不在范围内则return (数据水了)更好的方法是标程上讲的分段Hash http://page.renren.com/601081183/not... 阅读全文
posted @ 2012-08-26 21:24 编程菜菜 阅读(425) 评论(0) 推荐(0) 编辑
摘要: 第一个离散化线段树先把区间写成左开右闭的形式,然后sort() unique() lower_bound() 离散化最后按普通线段树更新即可代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;#define for if(0); else forcons... 阅读全文
posted @ 2012-08-15 11:56 编程菜菜 阅读(984) 评论(0) 推荐(0) 编辑
摘要: 刚开始做的时候还以为是暴搜,YY了各种剪枝,结果华丽丽的TLE了正解:状态压缩DP dp[当前走到的点][状态] 状态: 第i位表示第i个点有没有被消灭转移: 详见代码注意: 计算转移cost时要用O(1) 的算法 二分会TLE代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#includ... 阅读全文
posted @ 2012-08-13 22:40 编程菜菜 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 线段树扫描线经典题:求矩形面积并思想:对y轴坐标离散化 分别计算各个小矩形的面积#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N=513;struct Rect{double x1,y1,x2,y2;};struct Sline{do... 阅读全文
posted @ 2012-08-12 22:35 编程菜菜 阅读(211) 评论(0) 推荐(0) 编辑