针对如下形式的ACM试题,大多出自南阳理工学院的在线ACM试题(网址: 南阳理工在线评测系统),在此非常感谢,同时也非常感谢作者的分享!
时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述

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>
 #include<string.h>
 int max(int a, int b){
     return (a>b)?a:b;
 }

 int main()
 {
     int n;
     ][];
     ][];
     scanf("%d", &n);
     ;
     ; i < n; ++i) {
         ; j < i+; ++j) {
             arr[i][j] = sumdpth[i][j] = ;
             scanf("%d", &arr[i][j]);
             sumdpth[i][j] = arr[i][j];
         }
     }

     ; i < n; ++i) {
         ; j < i+; ++j) {
             ){
                 sumdpth[i][j] = arr[i-][j];
             }
             sumdpth[i][j] = max(sumdpth[i-][j]+arr[i][j],sumdpth[i-][j-]+arr[i][j]) ;
             if(tmpmax < sumdpth[i][j]) tmpmax = sumdpth[i][j];
         }
     }

     printf("%d\n", tmpmax);
 /*
     for (int i = 0; i < n; ++i) {
         for (int j = 0; j < i+1; ++j) {
             printf("%d ", arr[i][j]);
         }
         printf("\n");
     }
     */

 }


The Triangle的更多相关文章

  1. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  2. [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, ...

  3. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  4. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  5. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  6. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  7. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

  8. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

  9. LeetCode 119 Pascal's Triangle II

    Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...

  10. 【leetcode】Triangle (#120)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

随机推荐

  1. C#网络爬虫 WebUtility使用 转义字符 urlCode

    背景: 在C#写网络爬虫时候,有时候需要将html中的转义字符进行处理,还有网址中的中文处理 一.html转义字符处理 1.ASP.NET中的html解析 HttpUtility.HtmlDecode ...

  2. 使用ASP.Net WebAPI构建REST服务(一)——简单的示例

    由于给予REST的Web服务非常简单易用,它越来越成为企业后端服务集成的首选方法.本文这里介绍一下如何通过微软的Asp.Net WebAPI快速构建REST-ful 服务. 首先创建一个Asp.Net ...

  3. CentOS 6.5安装Apache

    1.Apache的特点 功能强大.配置简单.速度快.应用广泛.性能稳定可靠,并可做代理服务器或负载均衡来使用 2.Apache的应用场合 使用Apache运行静态HTML网页.图片(处理静态小文件能力 ...

  4. Linux学习:用yum安装php,httpd,mysql

    见鸟哥的linux私房菜电子版832页.

  5. Error 0x800704cf

    重装了系统,改过网络配置,结果共享和打印机连不上,显示Error 0x800704cf 在本地连接的属性里将"Client for Microsoft Networks"勾选上就可 ...

  6. MySQL中的运算符

    一.算法运算符: (A) 除法运算和模运算中,如果除数为0,非法,返回结果为NULL. 二.比较运算符: (A) 比较结果不确定是返回NULL. (B) 比较运算符可以用于比较数字.字符串和表达式.数 ...

  7. http://five-js.envylabs.com/

    一个很有意思的播报javascript最新资讯的网站http://five-js.envylabs.com/

  8. sql server 2008 R2 不允许保存更改,您所做的更改要求删除并重新创建以下表

    点击菜单栏 [工具]->[选项] 进入如下界面: 将阻止保存要求重新创建表的更改 的勾去掉即可.

  9. 多版本python共存

    当不同版本python之间相互不能兼容时,可以使用virtualenv创建不同版本python的虚拟环境 当没有指定python解释器时(如下-p 即为指定的python版本),将使用默认的全局pyt ...

  10. Tunna内网转发

    Tunna和reduh原理一样.. 使用方法: 上传源码包中文件夹webshell下的脚本至网站目录 然后本地进行连接上传的webshell即可 python proxy.py -u http://1 ...