The Triangle
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 44998   Accepted: 27175

Description

7
3 8
8 1 0
2 7 4 4
4 5 2 6 5 (Figure 1)

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
7
3 8
8 1 0
2 7 4 4
4 5 2 6 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 记忆化搜索的更多相关文章

  1. POJ 1088 滑雪(记忆化搜索)

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description ...

  2. POJ 3176-Cow Bowling(DP||记忆化搜索)

    Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14210   Accepted: 9432 Desc ...

  3. POJ 1088 滑雪 DFS 记忆化搜索

    http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...

  4. POJ 1088 滑雪【记忆化搜索】

    题意:给出一个二维矩阵,要求从其中的一点出发,并且当前点的值总是比下一点的值大,求最长路径 记忆化搜索,首先将d数组初始化为0,该点能够到达的路径长度保存在d数组中,同时把因为路径是非负的,所以如果已 ...

  5. poj 1088 滑雪_记忆化搜索

    题意:略 直接用记忆化搜索就行了 #include<cstdio> #include<iostream> using namespace std; int n,m; int m ...

  6. HDU 1501 & POJ 2192 Zipper(dp记忆化搜索)

    题意:给定三个串,问c串是否能由a,b串任意组合在一起组成,但注意a,b串任意组合需要保证a,b原串的顺序 例如ab,cd可组成acbd,但不能组成adcb. 分析:对字符串上的dp还是不敏感啊,虽然 ...

  7. POJ 1088 滑雪 【记忆化搜索经典】

    题目链接:http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:  ...

  8. POJ 3373 Changing Digits 记忆化搜索

    这道题我是看了别人的题解才做出来的.题意和题解分析见原文http://blog.csdn.net/lyy289065406/article/details/6698787 这里写一下自己对题目的理解. ...

  9. poj 1695 Magazine Delivery 记忆化搜索

    dp[a][b][c],表示三个人从小到大依次在a,b.c位置时.距离结束最少的时间. 每次选一个人走到c+1位置搜索就好了. 坑点在于不能floyd.预计题目没说清楚.意思就是假设没送Li,那么Li ...

随机推荐

  1. Document类

    一.类结构 org.jsoup.nodes Class Document java.lang.Object org.jsoup.nodes.Node org.jsoup.nodes.Element o ...

  2. C++学习(二):学会使用stringstream

    1.前言 今天在CppTemplateTutorial群里,有人问了一个问题:这一堆add怎么简化掉 https://wandbox.org/permlink/vDPDwMFbBIQSSymS.代码如 ...

  3. Fennec VS. Snuke --AtCoder

    题目描述 Fennec and Snuke are playing a board game.On the board, there are N cells numbered 1 through N, ...

  4. path.join 与 path.resolve 的区别

    1. 对于以/开始的路径片段,path.join只是简单的将该路径片段进行拼接,而path.resolve将以/开始的路径片段作为根目录,在此之前的路径将会被丢弃,就像是在terminal中使用cd命 ...

  5. 串口调试利器--Minicom配置及使用详解.md

    因为现在电脑基本不配备串行接口,所以,usb转串口成为硬件调试时的必然选择.目前知道的,PL2303的驱动是有的,在dev下的名称是ttyUSB*. Minicom,是Linux下应用比较广泛的串口软 ...

  6. ios界面笔记(二)

    1,在ios下实现checkbox的效果 主要思路是添加一个button,然后读取其isselected属性,分别添加不同的界面图片即可 具体实现如下: 2,解决两个window切换时消息无法送达 主 ...

  7. iOS UI Element Usage

    Bars The Status Bar

  8. iphone之判断屏幕方向

    有两种方法可以判断 1,程序刚开始运行的时候,不能获取当前方向.给你说几种方式,你试一下: 1. 可以在启动后0.01秒执行初始化的代码,这个时候就可以获取设备方向了. 2. 另外一种方式,借助状态栏 ...

  9. selenium用法 (python)

    滑动到指定元素位置 browser.find_element_by_xpath("//font[text()='资产管理部经办人'][1]").location_once_scro ...

  10. selenium firefox46.0.1设置禁用图片

     firefox_profile = webdriver.FirefoxProfile()firefox_profile.set_preference('permissions.default.ima ...