poj 1163 The Triangle 记忆化搜索
|
The Triangle
Description 7 Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right. Input Your program is to read from standard input. The first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rows in the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99.
Output Your program is to write to standard output. The highest sum is written as an integer.
Sample Input 5 Sample Output 30 Source |
#include<iostream>
#include<stdio.h>
using namespace std;
int n;
int ma[][];
int dp[][];
int dfs(int row,int col){
if(row>n) return ;
if(dp[row][col]) return dp[row][col];
dp[row][col]=ma[row][col]+max(dfs(row+,col),dfs(row+,col+));
return dp[row][col];
}
int main(){ while(~scanf("%d",&n)){
for(int i=;i<=n+;i++)
for(int j=;j<=n+;j++)
dp[i][j]=;
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
scanf("%d",&ma[i][j]);
}
}
printf("%d\n",dfs(,));
}
}
poj 1163 The Triangle 记忆化搜索的更多相关文章
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
- POJ 3176-Cow Bowling(DP||记忆化搜索)
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14210 Accepted: 9432 Desc ...
- POJ 1088 滑雪 DFS 记忆化搜索
http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...
- POJ 1088 滑雪【记忆化搜索】
题意:给出一个二维矩阵,要求从其中的一点出发,并且当前点的值总是比下一点的值大,求最长路径 记忆化搜索,首先将d数组初始化为0,该点能够到达的路径长度保存在d数组中,同时把因为路径是非负的,所以如果已 ...
- poj 1088 滑雪_记忆化搜索
题意:略 直接用记忆化搜索就行了 #include<cstdio> #include<iostream> using namespace std; int n,m; int m ...
- HDU 1501 & POJ 2192 Zipper(dp记忆化搜索)
题意:给定三个串,问c串是否能由a,b串任意组合在一起组成,但注意a,b串任意组合需要保证a,b原串的顺序 例如ab,cd可组成acbd,但不能组成adcb. 分析:对字符串上的dp还是不敏感啊,虽然 ...
- POJ 1088 滑雪 【记忆化搜索经典】
题目链接:http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- POJ 3373 Changing Digits 记忆化搜索
这道题我是看了别人的题解才做出来的.题意和题解分析见原文http://blog.csdn.net/lyy289065406/article/details/6698787 这里写一下自己对题目的理解. ...
- poj 1695 Magazine Delivery 记忆化搜索
dp[a][b][c],表示三个人从小到大依次在a,b.c位置时.距离结束最少的时间. 每次选一个人走到c+1位置搜索就好了. 坑点在于不能floyd.预计题目没说清楚.意思就是假设没送Li,那么Li ...
随机推荐
- svn提示出错异常为remains in conflict
查看原文:http://www.ibloger.net/article/225.html 提交冲突代码 commit -m "" E:/Program Files/MyEclips ...
- pat 团体天梯赛 L2-001. 紧急救援
L2-001. 紧急救援 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国 ...
- using要写多少
原文发布时间为:2009-10-25 -- 来源于本人的百度文章 [由搬家工具导入] 有时候未必要像默认的这样要using这么多。。。 using System;using System.Data;u ...
- [LeetCode] Number of 1 Bits 位操作
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---31
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- 《手把手教你学C语言》学习笔记(4)---代码规范
编程过程中需要遵守编译器的各种约定,例如以下代码: 1 #include <stdio.h> 2 3 int main(int argc, char **argv) 4 { 5 print ...
- C++序列化对象
需求 . 在写代码的过程中,经常会需要把代码层面的对象数据保存到文件,而这些数据会以各种格式存储.例如:json,xml,二进制等等.最近恰好就需要把对象以二进制存储到硬盘.这是一个很简单的需求,相比 ...
- Color.FromArgb()方法详解
关于颜色值的表示 常用的颜色值表示方式有两种,一种是10进制的RGB值表示,如(0,113,255),三个值分别表示(红,绿,蓝):一种是16进制的颜色码表示,如#ff3212.这两种形式在编程中都可 ...
- 判断scrollView的滑动方向
第一种方式: float lastContentOffset; - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { las ...
- Cryptography I 学习笔记 --- 分组密码
1. 伪随机置换(PRF,Rseudo Random Permutaion)3DES/AES,K*X -> X(a. 可以高效计算,b. PRF函数是一个一一映射的函数,c. 存在有效的逆向算法 ...