【UVA】10285-Longest Run on a Snowboard(动态规划)
这是一个简单的问题。你并不需要打印路径。
状态方程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(动态规划)的更多相关文章
- UVA 10285 - Longest Run on a Snowboard (记忆化搜索+dp)
Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 seconds Memor ...
- UVA 10285 Longest Run on a Snowboard(记忆化搜索)
Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...
- UVa 10285 Longest Run on a Snowboard - 记忆化搜索
记忆化搜索,完事... Code /** * UVa * Problem#10285 * Accepted * Time:0ms */ #include<iostream> #includ ...
- UVa 10285 Longest Run on a Snowboard【记忆化搜索】
题意:和最长滑雪路径一样, #include<iostream> #include<cstdio> #include<cstring> #include <c ...
- UVa 10285 - Longest Run on a Snowboard
称号:给你一个二维矩阵,找到一个点.每一个可以移动到的位置相邻的上下,求最长单调路径. 分析:贪婪,dp.搜索. 这个问题是一个小样本,我们该怎么办. 这里使用贪心算法: 首先.将全部点依照权值排序( ...
- 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)处 ...
- UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)
题意:在一个R*C(R, C<=100)的整数矩阵上找一条高度严格递减的最长路.起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩阵外.矩阵中的数均为0~100. 分析:dp[x ...
- [动态规划]UVA10285 - Longest Run on a Snowboard
Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...
- 【Uva 10285】Longest Run on a Snowboard
[Link]: [Description] 在一个r*c的格子上; 求最长的下降路径; [Solution] 记忆化搜索; f[x][y]表示从(x,y)这个格子往下还能走多远; 因为是严格递增,所以 ...
随机推荐
- 为什么在Python3.4.1里输入print 10000L或10000L失败
打开Python的命令行交互窗体,而且在里面进行以下的输入: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 ...
- Linux 的 Shell
一个:Shell 概念 shell 这个词是不奇怪,意思是 "壳" 这是间OS 用户和芯层之间的相互作用,在linux系统.用户可以通过命令终端.使用shell 命令向下传达他们的 ...
- Android异步载入全解析之IntentService
Android异步载入全解析之IntentService 搞什么IntentService 前面我们说了那么多,异步处理都使用钦定的AsyncTask.再不济也使用的Thread,那么这个Intent ...
- B/S在北大青鸟-ASP.NET 总结
一个.前言: 这几周跟着于海涛老师进入了.NET编程世界.领略到了ASP.NET的精髓. 要说起ASP.NET的发展史,那要追溯到HTML了,由于它功能简单,无法从用户接收信息并自己主动进行更新.而不 ...
- Qt Mac 在软件 icns图标制作
1.首先,下载一个电话Icon Composer软件 之前Xcode像这个东西,现在,我不知道有或无,迷茫,一世Xcode很少. Icon Composer是苹果出的. 下载地址: http://ww ...
- 高通公司 MSM8K GPT异常原因分析无法开机的问题
问题分析过程如下面: 一. MSM8916台gpt概率问题:采用QPST emmc software download下载软件工具后,无法开机.例如下面的附图: log分析是userdata分区未成功 ...
- 联想G480安装CentOS电缆驱动器
最近.联想G480 32本机安装现场CentOS 6.5. 发现.总是无法使用有线网络. 必须安装必要的驱动,搜集了资料,安装过程例如以下: 1. 必备的软件 安装前,须要下列的软件依赖包. sudo ...
- Windows Phone获取WiFi BSSID
原文:Windows Phone获取WiFi BSSID BSSID,一种特殊的Ad-hoc LAN的应用,也称为Basic Service Set (BSS),一群计算机设定相同的BSS名称,即可自 ...
- Java Main如何被执行?(转)
java应用程序的启动在/hotspot/src/share/tools/launcher/java.c的main()函数中,而在虚拟机初始化过程中,将创建并启动Java的Main线程.最后将调用JN ...
- zoj 3537 Cake (凸包确定+间隔dp)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...