【单调性dp】bzoj 1499
来源:互联网 发布:cpa软件是什么意思啊 编辑:程序博客网 时间:2024/05/04 10:16
http://www.lydsy.com/JudgeOnline/problem.php?id=1499
//#pragma comment(linker, "/STACK:102400000,102400000")#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;/*bzoj 1499对于向上,划w单位时间:dp[i][x][y] = Max(dp[i-1][x1][y]+-x1)+x;(x1>=x&&x1<=x+w)简化空间:滚动数组简化时间:单调队列优化*/const int N = 1010;int n,m;char s[N][N];int dp[2][N][N];int que[N],qid[N];int op,w;int Tox[] = {0,-1,1,0,0}, Toy[] = {0,0,0,-1,1};void solve(int x,int y,int to){ int id=1; int head=1, tail=0; while(x>=1 && x<=n && y>=1 && y<=m){ //printf("x:%d y:%d\n",x,y); if(s[x][y]=='x') head=1, tail=0; while(head<=tail && dp[op^1][x][y]-id>que[tail]) tail--; while(head<=tail && id-w>qid[head]) head++; que[++tail]=dp[op^1][x][y]-id; qid[tail]=id; if(head>tail) dp[op][x][y]=-INF; else dp[op][x][y]=max(dp[op][x][y],que[head]+id); id++; x+=Tox[to], y+=Toy[to]; }}int main(){ int x,y,k; scanf("%d%d%d%d%d",&n,&m,&x,&y,&k); for(int i = 1; i <= n; i++) scanf("%s",s[i]+1); for(int i = 0; i < 2; i++) for(int j = 0; j <= n; j++) for(int k = 0; k <= m; k++) dp[i][j][k] = -INF; op = 0; dp[op][x][y] = 0; for(int q = 1; q <= k; q++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); w = b-a+1; //chang du op = op^1; if(c == 1) for(int j = 1; j <= m; j++) solve(n,j,c); else if(c == 2) for(int j = 1; j <= m; j++) solve(1,j,c); else if(c == 3) for(int i = 1; i <= n; i++) solve(i,m,c); else for(int i = 1; i <= n; i++) solve(i,1,c); } int mx = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) mx=max(mx,dp[op][i][j]); printf("%d\n",mx); return 0;}
阅读全文
0 0
- 【单调性dp】bzoj 1499
- Bzoj:[Poi2011]Lightning Conductor:决策单调性优化DP详解
- [BZOJ 2216][Poi2011]Lightning Conductor 单调性dp
- [BZOJ 2216][Poi2011]Lightning Conductor:DP决策单调性
- BZOJ 1563: [NOI2009]诗人小G 决策单调性DP
- BZOJ 2216: [Poi2011]Lightning Conductor 决策单调性DP
- bzoj 2216: [Poi2011]Lightning Conductor(DP决策单调性)
- bzoj 4709: [Jsoi2011]柠檬(分段DP+决策单调性)
- [BZOJ]4709 柠檬 DP单调性优化 + 单调栈
- 【单调性dp】Vijos 1243
- HNOI 2008 玩具装箱 (BZOJ 1010)进一步学习 →.→ DP 单调性优化
- [决策单调性 分治||单调栈 DP] BZOJ 2739 最远点
- bzoj 1071 [SCOI2007]组队 单调性
- BZOJ 1071: [SCOI2007]组队【单调性扫一遍
- hdu5064 Find Sequence 单调性dp
- [BZOJ1010]玩具装箱:DP决策单调性
- bzoj4709 -- 决策单调性优化DP
- bzoj2369 && 2687 -- 决策单调性优化DP
- Mac 的 入门
- 驱动模块Makefile解析
- JN项目-封面管理增加下拉场馆选项
- 图像处理(四):边缘检测(一):
- Unity打安卓包常见错误
- 【单调性dp】bzoj 1499
- Spring集成Quartz之作业类继承自特定的基类
- Android权限动态申请
- IDEA警告:SQL dialect is not configured
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink实战基础0011--flink分布式部署006
- 系统间通信方式之(ActiveMQ的基础使用参数详解2)(十三)
- main函数带参数
- HDU1166 线段树 单点修改、区间查询
- 编译VPP报错