C语言的实现,Adding up Triangles怎么做

Problem Description
Take a look at the triangle on the left of the figure below. It is made of 9 (unit) triangles arranged in three rows (N = 3 ). Needless to say, a unit triangle is a triangle with N = 1 .

If you study the figure for few seconds, you'll realize that you can find 13 different triangles (which we'll call sub-triangles.) Of these 13 sub-triangles we have: Nine unit triangle; three with N = 2 , and one with N = 3 . The following table lists the number of sub-triangles in arrangements with N < 5 .

Let's define the value of a unit triangle to be the integer value written in that triangle. In general, the value of a triangle is the sum of values in all its unit triangles. The triangle on the right is the same as the other one but with the sub-triangle having the largest value being highlighted. Write a program to determine the sub-triangle with the largest value.

Input
Your program will be tested on one or more test cases. Each test case is specified in a single line made of integers (separated by spaces.) The first integer is the number of rows in the test case, and the remaining integers are the values of the unit triangles specified in a top-down, left-to-right order. (the first test case in the example below is the same as the one in the figure.) The last line of the input file contains the number 0 (which is not part of the test cases.)

The maximum number of rows is 400. The absolute value of a unit triangle is less than 1000.

Output
For each test case, print the result using the following format:

k . V

where k is the test case number (starting at 1,) is a single space, and V is the maximum value of a sub-triangle in that test case.

Sample Input
3 6 -24 0 12 -10 12 40 -4 6
4 1 1 -1 1 1 -1 1 -1 1 1 -1 1 -1 1 -1 1
0

Sample Output
1. 54
2. 4

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

2
用make进行编译的时候,提示error adding symbols
0
RP问题的概率的联合分布律求解,采用的是C语言的思路的相关的做法
0
数据的分布的判断怎么实现的,用C程序的程序的设计的语言怎么做的
0
积木的堆叠的一个算法的实现,怎么利用C语言的程序的设计的方式来编写
0
三张纸牌连成一组的算法的实现,运用C程序的语言的编写设计的实现的思路的过程
1
C#操作OutLook发邮件失败
0
SSL_connect failed,err code=-155;做ssl连接aws服务器的时候,出现一直ssl_connect failed。
0
写程序判断三张扑克牌比赛的获胜者,用C语言技术编写出的程序的代码编写程序如何判断的呢
0
将给定的单词列表转换为字典的算法原理,是如何使用C语言的程序编写设计的思想方法的代码怎么来做
1
编译PX4时出现下面错误怎么办error: non-constant condition for static assertion
0
dom4j:Adding text to an XML document must not be null
0
找零钱的一个编程的问题,怎么采用C语言的程序的编写设计的过程的方式来实现代码的
0
搭砖块的排列方式的问题,怎么采用C语言的程序的编写的设计的技术怎么实现这个排列组织的
1
两端插入的数组的计算的实现问题,怎么采用C程序的语言的编程的方式去实现的算法计算
0
三符号状态的矩阵联合,怎么使用C语言的代码的设计的技术的办法来实现呢
1
kettle的JOB互相嵌套的作业,在windows上正常运行,迁移到Linux服务器就报错了
0
轨道连通性的一个问题计算,怎么用C语言
0
金钱的比例的计算问题,用 C语言的办法
1
spark 读取不到hive metastore 获取不到数据库
1
在训练Tensorflow模型(object_detection)时,训练在第一次评估后退出,怎么使训练继续下去?