1000: Several towers

Source: Internet
Author: User

1000: Tower time limit: 1 Sec memory limit: MB
Submissions: 683 Resolution: 297
Submitted State [Discussion Version] Title Description

Given a number of towers, as shown in. In this tower, from the top, at each node you can choose to go down to the lower left or lower right, always go to the bottom. Please find a path to make the value on the path and maximum.

9

12

15

10

6

8

2

18

9

5

19

7

10

4

16

Input

The first line of input is an integer n, which indicates the number of rows of the tower, and the remaining n rows represent the values of each row of the tower.

Output

The output contains two rows, the sum of the values on the maximum path of the first behavior, and the second row n digits from the top down to the maximum path value

Sample input
5912 1510 6 82 18 9 519 7 10 4 16
Sample output
599 12 10) 18 10
Hint Source

#include <iostream>
using namespace Std;
int main () {
int n,i,j;
int a[100][100],b[100][100],c[100][100];
cin>>n;
for (i=0;i<n;i++) {
for (j=0;j<=i;j++) {
cin>>a[i][j];
}
}
for (i=0;i<n;i++) {
B[n-1][i]=a[n-1][i];
}
for (i=n-2;i>=0;i--) {
for (j=0;j<=i;j++) {
if ((A[i][j]+b[i+1][j]) > (a[i][j]+b[i+1][j+1]) {
c[i][j]=0;
B[I][J]=A[I][J]+B[I+1][J];
}else{
C[i][j]=1;
B[I][J]=A[I][J]+B[I+1][J+1];
}
}
}
cout<<b[0][0]<<endl;
cout<<a[0][0];
j=0;
for (i=0;i<n-1;i++) {
J=J+C[I][J];
cout<< "" <<a[i+1][j];
}
cout<<endl;
return 0;
}

1000: Several towers

Contact Us

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.