poj 1088 滑雪
来源:互联网 发布:上海银行 淘宝金卡 编辑:程序博客网 时间:2024/06/07 12:26
记忆化搜索。。
对每个点能走的最远进行记录,如果走过,直接返回上一层。。
最后遍历找出最大值。。
<span style="font-size:18px;">#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;struct node{ int q,w;}s[104][105];int a,b;int yy[105][105];int map[4][2]={1,0,-1,0,0,1,0,-1};int dfs(int c,int d){ if(s[c][d].w!=1) { return s[c][d].w; } int n,m,max=0; for(int i=0;i<4;i++) { int e=c+map[i][0]; int f=d+map[i][1]; if(e>0&&e<=a&&f<=b&&f>0&&s[c][d].q>s[e][f].q) { if(max<dfs(e,f)) s[e][f].w=max=dfs(e,f);//这记录着每个点走的距离,但是没有对最终返回的值进行记录,少这个会超时 } } return max+1;}int main(){ scanf("%d %d",&a,&b); for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { scanf("%d",&s[i][j].q); s[i][j].w=1; } } int maxn; for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { // memset(yy,0,sizeof(yy)); if(s[i][j].w==1) { maxn=dfs(i,j); s[i][j].w=maxn;//记录最终返回的值 } } } for(int i=1;i<=a;i++) { for(int j=1;j<=b;j++) { // printf("%d\n",s[i][j].w); if(s[i][j].w>maxn) maxn=s[i][j].w; } } printf("%d\n",maxn); return 0;}</span>
0 0
- POJ 1088 滑雪
- POJ 1088 滑雪
- POJ 1088 滑雪
- Poj 1088 滑雪
- poj 1088 滑雪
- 滑雪--POJ--1088
- poj 1088 滑雪(DP)
- POJ 1088 滑雪
- POJ 1088 滑雪
- poj 1088 滑雪
- POJ 1088 滑雪
- poj 1088 滑雪
- POJ 1088 滑雪
- poj 1088 滑雪
- poj 1088 滑雪
- POJ 1088 滑雪 DP
- POJ 1088 滑雪
- Poj 1088 滑雪
- Java反射机制
- ZOJ 4257 Most Powerful
- button 修改 title 和 image偏移量
- Hadoop_WordCount示例_运行详解
- 产品经理入职后要做的12件事
- poj 1088 滑雪
- UVa 165 - Stamps 解题报告(暴力)
- ASP.NET Cookie的存储与读取
- HDU - 2276 Kiki & Little Kiki 2
- vc++取得系统信息,并实时刷新
- MyEclipse,Eclipse安装findBugs插件技巧
- 完美框架
- hdu-2018-母牛的故事
- Spring 父子容器(Spring配置的一个坑)