zoukankan      html  css  js  c++  java
  • 1220 数字三角形

    1220 数字三角形

     

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 黄金 Gold
     
     
     
    题目描述 Description

    如图所示的数字三角形,从顶部出发,在每一结点可以选择向左走或得向右走,一直走到底层,要求找出一条路径,使路径上的值最大。

    输入描述 Input Description

    第一行是数塔层数N(1<=N<=100)。

    第二行起,按数塔图形,有一个或多个的整数,表示该层节点的值,共有N行。

    输出描述 Output Description

    输出最大值。

    样例输入 Sample Input

    5

    13

    11 8

    12 7 26

    6 14 15 8

    12 7 13 24 11

    样例输出 Sample Output

    86

    数据范围及提示 Data Size & Hint
    数字三角形
     
     1 #include<iostream>
     2 using namespace std;
     3 int main() 
     4 {
     5     int n,i,j,a[101][101];
     6     cin>>n;
     7     for (i=1; i<=n; i++)
     8         for (j=1; j<=i; j++)
     9             cin>>a[i][j];                             //输入数字三角形的值
    10     for (i=n-1; i>=1; i--)
    11         for (j=1; j<=i; j++) 
    12         {
    13             if (a[i+1][j]>=a[i+1][j+1])  
    14             a[i][j]+=a[i+1][j];     //路径选择
    15             else  a[i][j]+=a[i+1][j+1];
    16         }
    17     cout<<a[1][1]<<endl;
    18 }
  • 相关阅读:
    php 延迟静态绑定: static关键字
    python分片
    用逗号分隔数字,神奇
    ubuntu 屏幕截图
    js 获取随机数
    netty : NioEventLoopGroup 源码分析
    LinkedList 源码分析
    面向对象
    JS
    网页
  • 原文地址:https://www.cnblogs.com/lyqlyq/p/6598942.html
Copyright © 2011-2022 走看看