The Triangle--nyoj 18
The Triangle
- 描述
-
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
其实就是一个简单的dp思想,每一步都去了最优值从而达到整体最优
代码
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[1010][1010],i,j,n,sum;
int main()
{
memset(a,0,sizeof(a));
sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
scanf("%d",&a[i][j]);
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=i*2-1;j++)
{
a[i][j]=max(a[i][j]+a[i+1][j],a[i][j]+a[i+1][j+1]);
}
}
printf("%d\n",a[1][1]);
return 0;
}
The Triangle--nyoj 18的更多相关文章
- NYOJ 18 The Triangle 填表法,普通dp
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=18 The Triangle 时间限制:1000 ms | 内存限制:6553 ...
- nyoj 18 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 ...
- Geometry and Appearances【转】
https://github.com/AnalyticalGraphicsInc/cesium/wiki/Geometry-and-Appearances Geometry and Appearanc ...
- acdream.18.KIDx's Triangle(数学推导)
KIDx's Triangle Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Sub ...
- nyoj 18-The Triangle(动态规划)
18-The Triangle 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:5 submit:5 题目描述: 7 3 8 8 1 0 2 7 4 ...
- NYOJ-102 次方求模 AC 分类: NYOJ 2014-02-06 18:53 184人阅读 评论(0) 收藏
地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=102 //a^b mod c=(a mod c)^b mod c很容易设计出一个基于二分的递归 ...
- NYOJ-20 吝啬的国度 AC 分类: NYOJ 2014-01-23 12:18 200人阅读 评论(0) 收藏
#include<cstdio> #include<cstring> #include<vector> using namespace std; int pre[1 ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- 设计一个程序,程序中有三个类,Triangle,Lader,Circle。
//此程序写出三个类,triangle,lader,circle:其中triangle类具有类型为double的a,b,c边以及周长,面积属性, //具有周长,面积以及修改三边的功能,还有判断能否构成 ...
- Think Python - Chapter 18 - Inheritance
In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...
随机推荐
- 拖入浏览器读取文件demo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Eigen与Matlab语法及语义辞典
Eigen为Matlab转换为C++提供了一个简单的语法级别的代码迁移工具. 对一些代码进行了扩充,以便程序由Matlab到Eigen的移植................... 参考链接:http: ...
- 【C++】颜色的设置
1.改变整个控制台的颜色用 system("color 0A"); 其中color后面的0是背景色代号,A是前景色代号.各颜色代码如下: 0=黑色 1=蓝色 2=绿色 3=湖蓝色 ...
- mvc重定向
出处 : https://www.cnblogs.com/lgxlsm/p/5441149.html .重定向方法:Redirect / RedirectToAction / RedirectToRo ...
- 插入DOM元素
插入Dom元素两种情况: 1.要插入的元素是从页面中获取的dom结构 ,例如:$(".item") 2.要插入的元素是通过变量存储的dom结构,例如:var html = &quo ...
- 15.3 Task Task.Yield和Task.Delay说明
https://blog.csdn.net/hurrycxd/article/details/79827958 书上看到一个Task.Yield例子,Task.Yield方法创建一个立即返回的awai ...
- [kernel学习]----如何debug kernel
#ll /sys/kernel/debug/tracing/events/kmem total 0 -rw-r--r-- 1 root root 0 Feb 3 20:17 enable -rw-r- ...
- emmmmmm(官宣?)
实验室永远不会是学习的唯一地点,不是吗? 总后悔当初退竞赛,现在却还是选择退出,大概是自己真的不适合吧...
- [Ynoi2015]即便看不到未来
题目大意: 给定一个序列,每次询问,给出一个区间$[l,r]$. 设将区间内的元素去重后重排的数组为$p$,求$p$中长度为$1\sim 10$的极长值域连续段个数. 长度为$L$的极长值域连续段的定 ...
- linux中php项目无法发送邮件:PEAR mail package is not installed
发送邮件报错误:PEAR mail package is not installed的原因是linux中缺少PEAR mail组件, PEAR mail组件也就是PHP Pear Mail / SMT ...