当前位置:网站首页>D - 滑雪
D - 滑雪
2022-06-26 12:40:00 【YJEthan】
Description
1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。
Input
Output
Sample Input
5 5 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Sample Output
25
dfs+dp
dp1[x][y]表示改点是否被访问 dp2[x][y]表示改点最长的滑雪区间
注意边界区域
代码如下
#include<stdio.h> #include<string.h> int a[1001][1001],dp1[1001][1001],dp2[1001][1001]; int n,m; int max(int a,int b) { if(a>b) b=a; return b; } int dfs(int x,int y) { if(x>n) return -1; if(x<1) return -1; if(y>n) return -1; if(y<1) return -1; if(dp1[x][y]!=-1) return dp2[x][y]; dp1[x][y]++; dp2[x][y]=1; if(a[x][y]>a[x+1][y]) { dp2[x][y]=max(dp2[x][y],dfs(x+1,y)+1); } if(a[x][y]>a[x][y+1]) { dp2[x][y]=max(dp2[x][y],dfs(x,y+1)+1); } if(a[x][y]>a[x-1][y]) { dp2[x][y]=max(dp2[x][y],dfs(x-1,y)+1); } if(a[x][y]>a[x][y-1]) { dp2[x][y]=max(dp2[x][y],dfs(x,y-1)+1); } return dp2[x][y]; } int main() { int i,j; int max0=0; while(scanf("%d%d",&n,&m)!=EOF) { for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%d",&a[i][j]); } } memset(dp1,-1,sizeof(dp1)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { max0=max(max0,dfs(i,j)); } } printf("%d\n",max0); }return 0; }
边栏推荐
- UVa11582 [快速幂]Colossal Fibonacci Numbers!
- code force Party Lemonade
- solo 博客系统的 rss 渲染失败
- 【网络是怎么连接的】第二章(中):一个网络包的发出
- J - Wooden Sticks poj 1065
- 详细讲解C语言11(C语言系列)
- Redis learning - 05 node JS client operation redis and pipeline pipeline
- goto语句实现关机小程序
- ES6:迭代器
- Basic principle and application routine of Beifu PLC rotary cutting
猜你喜欢

Beifu PLC passes MC_ Readparameter read configuration parameters of NC axis

【网络是怎么连接的】第二章(上): 建立连接,传输数据,断开连接

Stream learning record

倍福TwinCAT3 NCI在NC轴界面中的基本配置和测试
![Vivado 错误代码 [DRC PDCN-2721] 解决](/img/de/ce1a72f072254ae227fdcb307641a2.png)
Vivado 错误代码 [DRC PDCN-2721] 解决
![P5733 [deep foundation 6. example 1] automatic correction](/img/34/081dbd805593a92a86c3081d6772e3.png)
P5733 [deep foundation 6. example 1] automatic correction

倍福NC轴状态转移图解析

Redis learning - 05 node JS client operation redis and pipeline pipeline

初识-软件测试

倍福TwinCAT通过Emergency Scan快速检测物理连接和EtherCAT网络
随机推荐
Electron official docs series: Best Practices
Splunk iowait 报警的解决
Tiger DAO VC产品正式上线,Seektiger生态的有力补充
初识-软件测试
微信小程序测试点总结
无人机遥感在森林监测的部分应用研究案例总结
国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
QT .pri 的建立与使用
记一次phpcms9.6.3漏洞利用getshell到内网域控
Summary of some application research cases of UAV Remote Sensing in forest monitoring
Go 结构体方法
map 取值
KVM video card transparent transmission -- the road of building a dream
不到40行代码手撸一个BlocProvider
Stream learning record
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
倍福EtherCAT Xml描述文件更新和下载
Beifu PLC passes MC_ Readparameter read configuration parameters of NC axis
MySQL 自定义函数时:This function has none of DETERMINISTIC, NO SQL 解决方案
不到40行代码手撸一个BlocProvider