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 ...
随机推荐
- 2018华南理工大学程序设计竞赛 H-对称与反对称
H-对称与反对称 题目描述 给出一个N*N的方阵A.构造方阵B,C: 使得A = B + C.其中 B为对称矩阵,C为反对称矩阵. 对于方阵S中的任意元素,若(S)ij = (S)ji,则称S为对称矩 ...
- pat 团体天梯赛 L2-004. 这是二叉搜索树吗?
L2-004. 这是二叉搜索树吗? 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一棵二叉搜索树可被递归地定义为具有下列性质的 ...
- 【HDOJ5514】Frogs(容斥原理)
题意:n个青蛙在一个有m个节点的圆上跳,m个节点的标号为0-m-1,每只青蛙每次跳的节点数给出,让求n只青蛙所跳位置标号之和 n<=1e4,m<=1e9,a[i]<=1e9 思路:由 ...
- Page_Load与Page_PreRender的执行顺序
原文发布时间为:2009-10-25 -- 来源于本人的百度文章 [由搬家工具导入] Page_PreRender 服务器控件将要呈现给其包含的 控件时发生。简单的理解为page中的控件渲染调用此事件 ...
- 让Dropdownlist既有静态项又有动态项或者既能有编辑项又能绑定数据源
原文发布时间为:2008-10-27 -- 来源于本人的百度文章 [由搬家工具导入] protected void Page_Load(object sender, EventArgs e) //Dr ...
- Oracle 安装前准备
[root@localhost Desktop]# groupadd -g 110 oinstall 用来安装oracle软件 [root@localhost Desktop]# groupadd - ...
- IntelliJ IDEA设置鼠标移动到方法上提示API注释
参考: https://www.cnblogs.com/guazi/p/6474426.html(图片转自此篇文章)
- 缺少 Google API 秘钥,因此 Chromium 的部分功能将无法使用
获取密钥(ID)教程: https://www.chromium.org/developers/how-tos/api-keys 获取密钥(ID)地址: https://cloud.google.co ...
- 卸载django
首先找到django安装路径 Python import sys; sys.path = sys.path[1:]; import django; print(django.__path__) 得到 ...
- poor-pigs(非常好的思路)
https://leetcode.com/problems/poor-pigs/ package com.company; class Solution { // 下面第二种做法貌似是OJ原来的做法, ...