nyoj_18_The Triangle_201312071533
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
- 上传者
- 苗栋栋
-
#include <stdio.h> int main()
{
int s[][]={};
int i,j,n;
int max=,t;
scanf("%d",&n);
for(i=;i<=n;i++)
{
for(j=;j<=i;j++)
{
scanf("%d",&s[i][j]);
t=(s[i-][j]>s[i-][j-])?s[i-][j]:s[i-][j-];
s[i][j]+=t;
}
}
for(i=;i<=n;i++)
if(s[n][i]>max)
max=s[n][i];
printf("%d\n",max);
//while(1);
return ;
}//简单的动态规划
nyoj_18_The Triangle_201312071533的更多相关文章
随机推荐
- 【转载】HashMap底层实现原理及面试问题
①HashMap的工作原理 HashMap基于hashing原理,我们通过put()和get()方法储存和获取对象.当我们将键值对传递给put()方法时,它调用键对象的hashCode()方法来计算h ...
- Decode the Strings
http://acm.hdu.edu.cn/showproblem.php?pid=2371 题意:给出一个长度为n的字符串(标号为1~n),以及n个数代表字符串的变换规则,问该字符串是由哪个字符串按 ...
- 用vue-cli快速构建项目
用vue-cli脚手架快速构建项目的过程:1.首先要在node的环境下安装: 1>安装node:https://nodejs.org/en/(带npm,但是npm太慢了,建议安装cnpm,cnp ...
- dubbo+zookeeper下生产者和消费者配置(基于springboot开发)
一.总共分为三个目录: dubbo-api 服务的接口用于对接客户端和服务端 dubbo-client 客户端配置文件为:consumer.xml dubbo-service 服务 ...
- nginx入门学习
1.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了 yum install gcc patch libffi-devel python-devel zlib-devel bzip ...
- 自定义View(8)关于measure->onMeasur->setMeasuredDimension及getDefaultSize,resolveSizeAndState
参考: http://www.cnblogs.com/xiaorenwu702/p/5185436.html 当外层容器组件调用其内部的某个组件view1.measure(xxx)时,view1的on ...
- 解决:efi usb device has been blocked by the current security policy
解决:efi usb device has been blocked by the current security policy 问题描述:U盘装系统或者其他操作时,是因为BIOS安全策略,出现上述 ...
- 屏蔽scrollview的滚动
外层有scrollview时,手指移动方向跟滚动条方向相同时,会导致scrollview的滚动.此时如果不想滚动的话,可以在要接受ontouch的子视图,或者子子视图中的touch监听里加上v.get ...
- 01--TCP状态转换
参考大牛文章: http://www.cnblogs.com/qlee/archive/2011/07/12/2104089.html
- vm装xp安装成功后进入不了系统
1.如果是用虚拟光驱,你肯定步骤是先新建的虚拟机,再安装的虚拟光驱,所以会出现这样的问题.(请先安装虚拟光驱,再新建虚拟机,再用虚拟光驱加载镜像文件,问题解决)2.如果是直接使用的镜像,那么在GHOS ...