这是一个简单的问题。你并不需要打印路径。

状态方程dp[i][j] = max(dp[i-1][j],dp[i][j-1],dp[i+1][j],dp[i][j+1]);

14003395 10285

option=com_onlinejudge&Itemid=8&page=show_problem&problem=1226" style="margin:0px; padding:0px; color:rgb(153,0,0); text-decoration:none">Longest Run on a Snowboard

Accepted C++ 0.026 2014-08-07 11:43:51

枚举每一个点进行遍历,使用记忆化搜索。要不会超时。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<string>
#include<sstream>
#include<ctime>
using namespace std;
#define _PI acos(-1.0)
#define INF (1 << 10)
#define esp 1e-6
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pill;
/*===========================================
===========================================*/
#define MAXD 100 + 10
char name[MAXD];
int m,n,ans;
int dp[MAXD][MAXD];
int mat[MAXD][MAXD];
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
int DP(int x,int y){
if(dp[x][y] != -1)
return dp[x][y];
dp[x][y] = 1;
for(int i = 0 ; i < 4 ; i++){
int _x = dir[i][0] + x;
int _y = dir[i][1] + y;
if(_x >= 0 && _y >=0 && _x < n && _y < m && mat[x][y] < mat[_x][_y]){
dp[x][y] = max(dp[x][y],DP(_x,_y) + 1);
}
}
ans = max(ans,dp[x][y]);
return dp[x][y];
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s%d%d",name,&n,&m);
int pos_x,pos_y;
int MIN = INF;
memset(dp,-1,sizeof(dp));
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++){
scanf("%d",&mat[i][j]);
if(mat[i][j] < MIN){
MIN = mat[i][j];
pos_x = i;
pos_y = j;
}
}
ans = 0;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
DP(i,j);
printf("%s: %d\n",name,ans);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

【UVA】10285-Longest Run on a Snowboard(动态规划)的更多相关文章

  1. UVA 10285 - Longest Run on a Snowboard (记忆化搜索+dp)

    Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 seconds Memor ...

  2. UVA 10285 Longest Run on a Snowboard(记忆化搜索)

    Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...

  3. UVa 10285 Longest Run on a Snowboard - 记忆化搜索

    记忆化搜索,完事... Code /** * UVa * Problem#10285 * Accepted * Time:0ms */ #include<iostream> #includ ...

  4. UVa 10285 Longest Run on a Snowboard【记忆化搜索】

    题意:和最长滑雪路径一样, #include<iostream> #include<cstdio> #include<cstring> #include <c ...

  5. UVa 10285 - Longest Run on a Snowboard

    称号:给你一个二维矩阵,找到一个点.每一个可以移动到的位置相邻的上下,求最长单调路径. 分析:贪婪,dp.搜索. 这个问题是一个小样本,我们该怎么办. 这里使用贪心算法: 首先.将全部点依照权值排序( ...

  6. UVA - 10285 Longest Run on a Snowboard (线性DP)

    思路:d[x][y]表示以(x, y)作为起点能得到的最长递减序列,转移方程d[x][y] = max(d[px][py] + 1),此处(px, py)是它的相邻位置并且该位置的值小于(x, y)处 ...

  7. UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)

    题意:在一个R*C(R, C<=100)的整数矩阵上找一条高度严格递减的最长路.起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩阵外.矩阵中的数均为0~100. 分析:dp[x ...

  8. [动态规划]UVA10285 - Longest Run on a Snowboard

    Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...

  9. 【Uva 10285】Longest Run on a Snowboard

    [Link]: [Description] 在一个r*c的格子上; 求最长的下降路径; [Solution] 记忆化搜索; f[x][y]表示从(x,y)这个格子往下还能走多远; 因为是严格递增,所以 ...

随机推荐

  1. MEF初体验之十二:Composition Batch

    一个MEF容器实例是不可变的.如果catalog支持改变(像观察一个目录的改变)或是如果你的代码在运行时添加或移除部件,改变都可能发生.以前,你不得不作出改变并在组合容器上调用它的组合方法.在Prev ...

  2. 关于.NET,.NET Framework 和ASP.NET的总结

    .NET 1.1.        .NET是 Microsoft XML Web services 平台和技术. 1.2.        一个.NET应用是一个运行于.NET Framework之上的 ...

  3. 【Eclipse高速发展-文章插件】google V8,对于调试Nodejs

    安装的的时候能够通过 Help>Eclipse Marketplace的 搜索方式安装 或者 Help>Install New Software Name:googleV8 Locatio ...

  4. Java达到MySQL数据库备份(两)

    博客<Java实现MySQL数据库备份(一)>使用I/O流的方式实现了MySQL数据库的备份,这样的方法比較繁杂.以下介绍还有一种备份MySQL数据库的方法: import java.io ...

  5. JSON-C结构简介、使用

    官方站点介绍http://www.json.org JSON (JavaScript Object Notation) is a lightweight data-interchange format ...

  6. Dynamic proxy

    import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflec ...

  7. Deep Learning Papers

    一.Image Classification(Recognition) lenet: http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf alexn ...

  8. Android GPS获取当前经纬度坐标

    APP中可能会遇到一种需求,就是将当前所在位置的坐标传到server上,今天我提供三种途径去获取经纬度坐标信息,第一种是通过Android API来实现,另外一种通过百度地图API来实现,第三种通过天 ...

  9. .net下几种常用的对称加解密

    加密解密算法,太常用了,可是实在忍受不了十次八次之后还是要重头写,总是能告诉我原来的算法不好用(实际是压根不会用)的情况,不如直接写出来,再有人要直接给他看看,也顺便记录下算法,方便下新手大众. DE ...

  10. asp.net学习之 数据绑定控件--List数据绑定控件

    原文:asp.net学习之 数据绑定控件--List数据绑定控件 List控件(如 CheckBoxList.DropDownList.ListBox 和 RadioButtonList 类)继承自L ...