POJ 1088 滑雪(简单的记忆化dp)
又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,,
//看了题解做的简单的记忆化dp #include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int mp[][],dp[][];
int xx[]={,-,,};
int yy[]={,,,-};
int n,m;
int dfs(int x,int y)
{
int ans=;
if(dp[x][y])return dp[x][y];
for(int i=;i<;i++)
{
int dx=xx[i]+x,dy=yy[i]+y;
if(dx>=&&dy>=&&dx<n&&dy<m)
{
if(mp[dx][dy]>mp[x][y])
ans=max(ans,+dfs(dx,dy));
}
}
dp[x][y]=ans;
return ans;
}
int main()
{ while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<n;i++){
for(int j=;j<m;j++){
scanf("%d",&mp[i][j]);
dp[i][j]=;
}
}
for(int i=;i<n;i++)
for(int j=;j<m;j++)
dp[i][j]=dfs(i,j);
int maxx=;
for(int i=;i<n;i++)
for(int j=;j<m;j++)
maxx=maxx>dp[i][j]? maxx:dp[i][j];
printf("%d\n",maxx);
}
return ;
}
POJ 1088 滑雪(简单的记忆化dp)的更多相关文章
- poj 1088 动态规划+dfs(记忆化搜索)
滑雪 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Description Mi ...
- POJ 1088 滑雪(记忆化搜索+dp)
POJ 1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 107319 Accepted: 40893 De ...
- Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)
Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. ...
- UVA - 11324 The Largest Clique 强连通缩点+记忆化dp
题目要求一个最大的弱联通图. 首先对于原图进行强连通缩点,得到新图,这个新图呈链状,类似树结构. 对新图进行记忆化dp,求一条权值最长的链,每一个点的权值就是当前强连通分量点的个数. /* Tarja ...
- cf835(预处理 + 记忆化dp)
题目链接: http://codeforces.com/contest/835/problem/D 题意: 定义 k 度回文串为左半部分和右半部分为 k - 1 度的回文串 . 给出一个字符串 s, ...
- cf779D(记忆化dp)
题目链接: http://codeforces.com/problemset/problem/799/D 题意: 给出两个矩阵边长 a, b, 和 w, h, 以及一个 c 数组, 可选择 c 数组中 ...
- Codeforces1107E Vasya and Binary String 记忆化dp
Codeforces1107E 记忆化dp E. Vasya and Binary String Description: Vasya has a string \(s\) of length \(n ...
- POJ 1088 滑雪 记忆化DP
滑雪 Time Limit: 1000MS Memory Limit: 65536K Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度 ...
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
随机推荐
- UNIX网络编程——网络I/O模型
在学习UNIX网络编程的时候.一開始分不清 同步 和 异步,所以还是总结一下,理清下他们的差别比較好. IO分类 IO依据对IO的调度方式可分为堵塞IO.非堵塞IO.IO复用.信号驱动IO.异步IO. ...
- Codeforces Round #273 (Div. 2)C. Table Decorations 数学
C. Table Decorations You have r red, g green and b blue balloons. To decorate a single table for t ...
- git diff比较使用
git diff 等同于 git diff HEAD jiqing@ubuntu:/home/wwwroot/default/siemens/new_hotel$ git diff HEAD diff ...
- 【POJ 2559】 Largest Rectangle in a Histogram
[题目链接] http://poj.org/problem?id=2559 [算法] 单调栈 [代码] #include <algorithm> #include <bitset&g ...
- awk数据预处理
{ && $~/192.168/) host_name = $ ;i<NF;++i) { if($i~/192.168/) { split($i, a, "=" ...
- opensStack
- 36.面板Ext.Panel使用
转自:https://www.cnblogs.com/linjiqin/archive/2011/06/22/2086620.html 面板Ext.Panel使用 概要 1.Ext.Panel概述 2 ...
- json-server的关系图谱详解(Relationships)
json-server的关系图谱 json-server是非常好用的一款模拟REST API的工具,文档也很详细和全面.详情:json-server而其中的关系图谱是它非常强大的一个功能,可以非常方便 ...
- Boost.Build特点(译)
Boost.Build Boost.Build makes it easy to build C++ projects, everywhere. Boost.Build让构建C++项目在任何地方都很容 ...
- 如何读取 Json 格式文件
Json 源文件代码: [ { "Id": "0", "Name": "书籍", "Detail": ...