南阳理工oj_The Triangle
The Triangle
时间限制:1000 ms | 内存限制:65535 KB
难度:4
描述
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.
输入
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.
输出
Your program is to write to standard output. The highest sum is written as an integer.
样例输入
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
样例输出
30
上传者
苗栋栋
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;
int a[110][110], dp[110][110];
#define mem(a) memset(a, 0, sizeof(a))
int main() {
int n;
while (cin >> n) {
mem(a); mem(dp);
for (int i = 0; i<n; i++) {
for (int j = 0; j<=i; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i<n; i++) dp[n-1][i] = a[n-1][i];
for (int i = n-2; i>=0; i--) {
for (int j = i; j>=0; j--) {
dp[i][j] = max(a[i][j] + dp[i+1][j], a[i][j] + dp[i+1][j+1]);
}
}
cout << dp[0][0] << endl;
}
return 0;
}
南阳理工oj_The Triangle的更多相关文章
- 南阳理工 题目9:posters(离散化+线段树)
posters 时间限制:1000 ms | 内存限制:65535 KB 难度:6 描述 The citizens of Bytetown, AB, could not stand that ...
- 矩形嵌套 南阳理工ACM
描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a<c,b<d或者b<c,a<d(相当于旋转X90度).例如(1, ...
- 单调递增最长子序列(南阳理工ACM)
描述 求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4 输入 第一行一个整数0<n<20,表示有n个字符串要处理随后的n行,每行有一个字符串,该字符串 ...
- 南阳理工ACM 括号匹配问题,并求出使得括号能够匹配需要新增的最小括号数(括号匹配(二))
描述 给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起 ...
- 南阳理工ACM Skiing问题
描述 Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底 ...
- 南阳理工ACM1076--方案数量
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1076 分析: <span style="font-size:18px;& ...
- 南阳理工oj88--汉诺塔(一)
题目链接.http://acm.nyist.net/JudgeOnline/problem.php?pid=88 #include <stdio.h> /* //测试一下49999和500 ...
- 南阳理工ACM954--N!
http://acm.nyist.net/JudgeOnline/problem.php?pid=954 循环的可怕之处!! 所有的测试数据结果完全一样.只是超时!!TimeLimitExceeded ...
- 南阳理工ACM975--关于521
http://acm.nyist.net/JudgeOnline/problem.php?pid=975 这是我的源码.一直超时,一直超时. 还有itoa函数函数的使用.可以改成sprintf(str ...
随机推荐
- Python学习日记day3:数据类型
1.数据类型int :如1.2.4等, 用于计算 bool: True , False ,用户判断 str: 储存少量数据,进行操作.如:'fdasklfjfladfl','而而噩噩','1234' ...
- Java I/O---获取文件目录并写入到文本
首先获取指定目录下的所有文件目录,存入List集合中,然后创建文本文件将List遍历写入文本中保存. 1.主程序类 public class Test { /** * @param args */ p ...
- deepin系统下部署Python3.5的开发及运行环境
deepin系统下部署Python3.5的开发及运行环境 1 概述 由于最近要学习python接口自动化测试,所以记录一下相关学习经过及经验,希望对大家可以有所帮助. 2 下载 在python官网下载 ...
- Java容器---List
List 承诺可以将元素维护在特定的序列中.List 接口在Collection的基础上添加了大量的方法,使得可以在List的中间插入和移除元素. 有两种类型的List: -----基本的 ...
- 使用 JSON.parse 反序列化 ISO 格式的日期字符串, 将返回Date格式对象
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Sql 两个表left join 查左表最时间最大的一条记录显示
http://bbs.csdn.net/topics/350135010 参考 select * from a aa left join b bb on aa.id=bb.cid and bb.ad ...
- java自动化测试-http请求post
继上文的get请求http://www.cnblogs.com/xuezhezlr/p/7667995.html的简单讲解后,这篇文章大概说一下我所遇到的主要的post请求以及他的测试代码 上文介绍到 ...
- Robot Framework学习笔记(八)------ride标签使用
一.edit标签使用 1.导入库 点击 Edit 标签页右侧的"Library"按钮,来添加库.在添加库之前,首先库已经在 Python 下进行了安装.如,添加"Sele ...
- Python day02 三元运算
type 查看数据类型.2 **32 :2的32次方 .浮点的表示类型是小数,但是小数不仅仅包括浮点 浮点数用来处理实数,即带有小数的数字 三元运算: result = 值1 if 条件 el ...
- Android JNI so库的开发
build.gradle的配置 apply plugin: 'com.android.application'android { compileSdkVersion 26 buildToolsVers ...