BZOJ3208:花神的秒题计划Ⅰ(记忆化搜索DP)
Description
Input
第一行n,第二行开始n*n的地图,意义如上;接下来一个m,然后是m个命令,如上
Output
Sample Input
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25
5
C 1 1 3
Q
S 1 3 5 5
S 3 1 5 5
Q
Sample Output
3
样例解释:
第一个Q路线为:25->24->23->22….->3->2
第二个Q的路线为:10->9->2
HINT
100%的数据:1<=n<=700;1<=m<=1000000;其中Q、S、B操作总和<=100;
题中所有数据不超过2*10^9
Solution
暴力可过 心态崩了
Code
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #define N (709)
- using namespace std;
- int n,m,x,y,z,c,ans,a[N][N],f[N][N],lim[N][N];
- int dx[]={,,-,,},dy[]={,,,,-};
- char opt[];
- int DP(int x,int y)
- {
- if (lim[x][y]) return -;
- if (f[x][y]!=-) return f[x][y];
- f[x][y]=;
- for (int i=; i<=; ++i)
- {
- int xx=x+dx[i], yy=y+dy[i];
- if (xx< || xx>n || yy< || yy>n || a[x][y]<=a[xx][yy]) continue;
- f[x][y]=max(f[x][y],DP(xx,yy)+);
- }
- return f[x][y];
- }
- void Update(int x,int y,int xx,int yy,int opt)
- {
- for (int i=x; i<=xx; ++i)
- for (int j=y; j<=yy; ++j) lim[i][j]=opt;
- }
- inline int read()
- {
- int x=; char ch=getchar();
- while (ch<'' || ch>'') ch=getchar();
- while (ch>='' && ch<='') x=x*+ch-'',ch=getchar();
- return x;
- }
- int main()
- {
- n=read();
- for (int i=; i<=n; ++i)
- for (int j=; j<=n; ++j)
- a[i][j]=read();
- m=read();
- while (m--)
- {
- scanf("%s",opt);
- if (opt[]!='Q') x=read(),y=read(),z=read();
- if (opt[]=='C') a[x][y]=z;
- if (opt[]=='S') c=read(),Update(x,y,z,c,);
- if (opt[]=='B') c=read(),Update(x,y,z,c,);
- if (opt[]=='Q')
- {
- memset(f,-,sizeof(f)); ans=;
- for (int i=; i<=n; ++i)
- for (int j=; j<=n; ++j)
- ans=max(ans,DP(i,j));
- printf("%d\n",ans);
- }
- }
- }
BZOJ3208:花神的秒题计划Ⅰ(记忆化搜索DP)的更多相关文章
- bzoj3208: 花神的秒题计划Ⅰ
3208: 花神的秒题计划Ⅰ Time Limit: 16 Sec Memory Limit: 128 MBSubmit: 323 Solved: 211[Submit][Status] Desc ...
- 【记忆化搜索】bzoj3208 花神的秒题计划Ⅰ
暴力 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #de ...
- bzoj 3208 花神的秒题计划I
bzoj 3208 花神的秒题计划I Description 背景[backboard]: Memphis等一群蒟蒻出题中,花神凑过来秒题-- 描述[discribe]: 花花山峰峦起伏,峰顶常年被雪 ...
- 记忆化搜索(DP+DFS) URAL 1183 Brackets Sequence
题目传送门 /* 记忆化搜索(DP+DFS):dp[i][j] 表示第i到第j个字符,最少要加多少个括号 dp[x][x] = 1 一定要加一个括号:dp[x][y] = 0, x > y; 当 ...
- BZOJ-3208|记忆化搜索-花神的秒题计划Ⅰ
背景[backboard]: Memphis等一群蒟蒻出题中,花神凑过来秒题-- 描述[discribe]: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目. 我 ...
- bzoj3208:花神的秒题计划I
思路:因为Q.S.B操作总和不超过100,因此怎么暴力怎么写....当然记忆化搜索还是要的 #include<cstdio> #include<iostream> #inclu ...
- 【bzoj3208】花神的秒题计划Ⅰ
记忆化搜索 #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib ...
- 记忆化搜索 dp学习~2
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1331 Function Run Fun Time Limit: 2000/1000 MS (Java/ ...
- 【10.31校内测试】【组合数学】【记忆化搜索/DP】【多起点多终点二进制拆位Spfa】
Solution 注意取模!!! Code #include<bits/stdc++.h> #define mod 1000000007 #define LL long long usin ...
随机推荐
- SQL 之获取DATE类的年月日语句
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), GETDATE( ...
- IIS利用X-Forwarded-For获得来访者的真实IP
https://help.aliyun.com/knowledge_detail/37948.html
- Linux**系统实现log日志自动清理
Linux系统实现log日志自动清理 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- ssm项目快速搭建(注解)-依赖
父层jar包版本控制,管理配置 <!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</ ...
- 一款软件同时管理MySQL,MongoDB数据库
互联网应用开发日新月异,去年分布式应用都还大量使用springmvc+ zookeeper +dubbo,今年就被spring boot ,spring cloud微服务架构替换了,技术的更新换代太快 ...
- composer gitlab 搭建私包
一.建立私包git 1.执行composer init 根据提示生成composer.json 2.编辑composer.json 目录格式 { "name": "iar ...
- C# 圆角button
因为自带的button是尖角的不太好看 这里在网上找的一份代码改改做个自用的button,画的操作不局限于button也可以画其他的 using System; using System.Collec ...
- bat批处理中如何获取前一天日期
网上找了好久在批处理中生成前一日期的代码段 但网上找到的代码对 每个月的1号和每年的1号计算前一日期时,总会报错,然后要加很多的逻辑判断 想了想,可以用.net写个EXE程序,用.net实现获取前一日 ...
- sublime 在Mac终端下设置快捷打开方式
vi ~/.zshrc alias subl='open -a "Sublime Text"' source ~/.zshrc 打开 ~/.zshrc,然后写入第二行,然后执行第三 ...
- Document对象关于窗口的一些属性
在网上搜罗的,只为自己查用方便,不做他用 window.screen.availWidth 返回当前屏幕宽度(空白空间) window.screen.availHeight 返回当前屏幕高度(空白空间 ...