滑雪(简单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 每一个格子仅仅 ...
随机推荐
- 【编程题目】题目:定义 Fibonacci 数列 输入 n,用最快的方法求该数列的第 n 项。
第 19 题(数组.递归):题目:定义 Fibonacci 数列如下:/ 0 n=0f(n)= 1 n=1/ f(n-1)+f(n-2) n=2输入 n,用最快的方法求该数列的第 n 项. 思路:递归 ...
- osgconv 批量转换
@echo offfor /f "delims=" %%i in ('dir/b *.osg') do ( "osgconv.exe" "%%~ni. ...
- merge
当两个DataFrame相加的时候,如果,其中一个不全则会相加产生NA,所以必须一次性将数据的索引索引确定下来,然后对所有数据重建索引然后,填充0,再相加.否则有数据的和没数据的相加结果都变为了NA, ...
- NYOJ题目840吃花生
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAKdCAIAAABeSGNbAAAgAElEQVR4nO3dPXKkuvv28f8mnHshjn
- 20145206邹京儒《Java程序设计》第3周学习总结
20145206 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 4.1 定义类 class Clothes{ String color; char size; } publ ...
- mysql 只导数据不含表结构
mysqldump -t 数据库名 -uroot -p > xxx.sql
- MVC – 9.mvc整体请求流程
1.请求管道 2~5微软自己的验证,我们一般不用. 在全局配置文件中-已经配置一个路由过滤器-为第7个事件注册了路由方法 1.在application_start中向静态路由表注册了路由数据,在管 ...
- 22.访问者模式(Vistor Pattern)
using System; using System.Collections; namespace ConsoleApplication5 { /// <summary> /// 访问者模 ...
- Dubbo应用与异常记录
结合项目里使用暴露出的问题,对并发较多的核心业务或者对请求失败等敏感的业务场景不太建议使用Dubbo, 如电商的购买等行为,使用Dubbo就必须阅读源码,熟悉相关机制,或者直接自己造轮子. >& ...
- win10下安装Ubuntu + 修复Ubuntu引导
如何在已安装 Windows 10 的情况下安装 Linux(Ubuntu 15.04)双系统? - Microsoft Windows - 知乎http://www.zhihu.com/questi ...