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