针对如下形式的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. JVM内存监控工具 Jconsole

    -------------Jconsole监视远程的linux服务器上的tomcat ----------------------------- 1.linux服务器上的tomcat 的bin/cat ...

  2. ionic懒加载图片

    https://github.com/paveisistemas/ionic-image-lazy-load <script src="lib/ionic/js/ionic-image ...

  3. 教你搭建SpringMVC框架( 更新中、附源码)

    一.项目目录结构 二.SpringMVC需要使用的jar包 commons-logging-1.2.jar junit-4.10.jar log4j-api-2.0.2.jar log4j-core- ...

  4. caffe学习系列(4):视觉层介绍

    视觉层包括Convolution, Pooling, Local Response Normalization (LRN), im2col等层. 这里介绍下conv层. layer { name: & ...

  5. BZOJ 1355: [Baltic2009]Radio Transmission

    Description 一个字符串最短周期. Sol KMP. 最短周期就是 \(n-next[n]\) 证明: 当该字符串不存在周期的时候 \(next[n]=0\) 成立. 当存在周期的时候 \( ...

  6. PyQt4关闭最大化最小化取消双击最大化

    self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.CustomizeWindowHi ...

  7. Objective C 快速入门学习二

    Objective-C 类.对象.方法 1.编写一个复数类: #import <Foundation/Foundation.h>@interface Complex: NSObject / ...

  8. [转载]C++虚函数浅析

    原文:http://glgjing.github.io/blog/2015/01/03/c-plus-plus-xu-han-shu-qian-xi/ 感谢:单刀土豆 C++虚函数浅析 JAN 3RD ...

  9. SQL Server常用命令

    1.DECLARE DECLARE命令用于声明一个或多个局部变量.游标变量或表变量. 注:如果定义的变量是字符型,应该指定data_type表达式中其最大长度,否则系统认为其长度为1. declare ...

  10. CentOS 6.5 安装Python 3.5

    1.CentOS6.5 安装Python 的依赖包 yum groupinstall "Development tools" yum install zlib-devel bzip ...