# 4979 Count Tower

Source: Internet
Author: User

4979 Count Tower

time limit: 1 sspace limit: 32000 KBtitle level: Golden Gold SolvingTitle Description Description

There are several towers, starting from the top, choosing to go left or right on each node and go to the end. Requires finding a path that maximizes the sum of the paths.

13

11 8

12 7 26

6 14 15 8

12 7 13) 24 11

Enter a description Input Description

The first line enters a positive integer n

Next, from line 2nd to line n+1, enter the number of rows per line minus 1 positive integer m.

Output description Output Description

A total of two lines

The first line outputs the maximum sum;

The second line outputs the maximum path, separated by '-';

Sample input Sample Input

5

13

11 8

12 7 26

6 14 15 8

12 7 13) 24 11

Sample output Sample Output

86

13-8-26-15-24

Data range and Tips Data Size & Hint

40% data: n<=20, m<=1000

60% data: n<=60, m<=1050

Category labels Tags Click here to expandNo label The following:Number triangle + Output path AC Code:
`#include <cstdio>#include<algorithm>using namespacestd;BOOLD;intb[101][101],c[101][101],n,tot;intMain () {inti,j; scanf ("%d",&N);  for(i=1; i<=n;i++){         for(j=1; j<=i;j++) {scanf ("%d",&B[i][j]); C[I][J]=B[i][j]; }    }     for(i=n-1; i>=1; i--)         for(j=1; j<=i;j++) B[i][j]+=max (b[i+1][j],b[i+1][j+1]); printf ("%d\n%d-", b[1][1],c[1][1]); J=1;  for(intI=2; i<=n;i++){        if(b[i][j]>=b[i][j+1]) printf ("%d", C[i][j]); Else{printf ("%d", c[i][j+1]); J++; }        if(i!=N) printf ("-"); }    return 0;}`

4979 Count Tower

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.