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
    数字三角形
    //include<AC自动机>
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<string>
    int b[101][101];
    using namespace std;
    int main()
    {
        int n,maxn=-1;cin>>n;
        for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
        {
            cin>>b[i][j];
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                b[i][j]=max(b[i-1][j],b[i-1][j-1])+b[i][j];
            }
        }
        for(int j=1;j<=n;j++)
        {
            if(b[n][j]>maxn)
            maxn=b[n][j];
        }
        cout<<maxn;
        return 0;
    }
  • 相关阅读:
    URAL 1948 H
    int、long、long long取值范围
    Bonetrousle HackerRank 数学 + 思维题
    湖南省第十二届大学生计算机程序设计竞赛 problem A 2016
    Abbreviation ---- hackerrank
    POJ 3321 Apple Tree DFS序 + 树状数组
    HDU
    PICO CTF 2013 PHP 2: 85
    XSS进阶三
    XSS进阶二
  • 原文地址:https://www.cnblogs.com/sssy/p/6598838.html
Copyright © 2011-2022 走看看