滑雪(简单dp)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 81099 | Accepted: 30239 |
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
Source
/*times memy
79ms 304k
by orc
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int R, C;
int d[][], mat[][];//d[i][j]为从第i行第j列的位置开始出发所得到的最长路
int dir[][] = {{-,},{,-},{,},{,}};
int dp(int i,int j)
{
//printf("[%d],[%d],%d\n",i,j,s);
if(i < || i > R || j < || j > C) return ;
int& res = d[i][j];
if(res != -) return res;
res = ;
for(int k = ; k < ; ++k)
{
int ti = i + dir[k][], tj = j + dir[k][];
if(mat[i][j] > mat[ti][tj]){//这里wa了很多次,mat[i][j]必须 > mat[ti][tj],而不能 >=
res = max(res,dp(ti,tj) + );
}
}
return res;
}
void getans()
{
for(int i = ; i <= R; ++i)
for(int j = ; j <= C; ++j)
dp(i,j);
}
int main()
{
ios::sync_with_stdio();
cin >> R >> C;
for(int i = ; i <= R; ++i)
for(int j = ; j <= C ; ++j)
cin >> mat[i][j];
memset(d,-,sizeof d);
getans();
// d[3][3] = dp(3, 3, mat[3][3]);
int ans = ;
for(int i = ; i <= R; ++i)
for(int j = ; j <= C; ++j)
ans = max(ans,d[i][j]);
cout << ans << endl;
// }
}
滑雪(简单dp)的更多相关文章
- POJ1088:滑雪(简单dp)
题目链接: http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一 ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- codeforces Gym 100500H A. Potion of Immortality 简单DP
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
- Codeforces 41D Pawn 简单dp
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...
随机推荐
- IOS - 首次启动程序出现的画面介绍
1.在appdelegate.m中找到 “application:didFinishLaunchingWithOptions:” 通过NSUserDefaults 来进行判断 if (![[NSUse ...
- WAMP2.5 Forbidden
Forbidden You don't have permission to access /DuoLamPHP/index.php on this server. Apache/2.4.9 (Win ...
- September 23rd 2016 Week 39th Friday
Even a small star shines in the darkness. 星星再小,也会发光. In the darkness, even a small star can shine. N ...
- Centos以rpm方式进行安装MySql
安装过很多次mysql了,却没好好总结过,每次安装完了都忘,下次还要重新Google,这次总结下,自己以后也有的查. 1.安装采用的的rpm包的方式,安装前要先看系统内是否安装了旧版本的MySql和m ...
- python基础——使用元类
python基础——使用元类 type() 动态语言和静态语言最大的不同,就是函数和类的定义,不是编译时定义的,而是运行时动态创建的. 比方说我们要定义一个Hello的class,就写一个hello. ...
- python基础——定制类
python基础——定制类 看到类似__slots__这种形如__xxx__的变量或者函数名就要注意,这些在Python中是有特殊用途的. __slots__我们已经知道怎么用了,__len__()方 ...
- 字符匹配算法之KMP
KMP算法的精华在于从前往后,逐步循环地向前滑动搜索词,来最大限度地减少重复匹配次数,以达到提高效率的目的. 移动位数=已匹配字符数-最后一个匹配字符所对应搜索词的位置[从1开始]. 更加详细且具体的 ...
- wp8 入门到精通 仿QQPivot 提示数量
<Grid x:Name="LayoutRoot" Background="White"> <Grid Width="480&quo ...
- SQL常见错误及处理方法
1.情况:数据库引擎安装失败,报类似权限不足的错误 解决:可能由于计算机名和用户名相同导致,更改计算机名,卸载干净重装即可
- Arduino101学习笔记(五)—— 模拟IO
1.配置IO管脚 //***************************************************************************************** ...