zoukankan      html  css  js  c++  java
  • codevs——T1220 数字三角形

     时间限制: 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
    数字三角形
     
    棋盘DP
     1 #include <algorithm>
     2 #include <cstdio>
     3 
     4 using namespace std;
     5 
     6 int n,ans=-1e7;
     7 int map[105][105];
     8 int f[1105][1105];
     9 
    10 int main()
    11 {
    12     scanf("%d",&n);
    13     for(int i=1;i<=n;i++)
    14         for(int j=1;j<=i;j++)
    15             scanf("%d",&map[i][j]);
    16     for(int i=1;i<=n;i++)
    17         for(int j=1;j<=i;j++)
    18             f[i][j]=map[i][j]+max(f[i-1][j],f[i-1][j-1]);
    19     for(int i=1;i<=n;i++)
    20         ans=max(ans,f[n][i]);
    21     printf("%d",ans);
    22     return 0;
    23 }
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    fzu 2122
    hdu 4707 bellman
    sicily 10330. Cutting Sausages
    湖南省2016省赛题。1809: Parenthesis 线段树
    Panoramic Photography
    B. No Time for Dragons 贪心
    The Weakest Sith
    E. The Best among Equals
    Gym 101149I I
    AtCoder D
  • 原文地址:https://www.cnblogs.com/Shy-key/p/6740470.html
Copyright © 2011-2022 走看看