Describe
The number triangle must pass a certain point to make it go the distance and the maximum
Input format
Line 1th N, which represents n rows <=25
2nd to n+1 behavior each weight value
Section n+2 behavior two number x, y indicates the point that must pass
Output format
A value that passes through the X, y maximum path
Test Sample 1
Input
2
1
1 1
1 1
Output
2
Note
Each test point 1s
Topic Analysis:
This problem I do very violent, directly on the X line except the point of Y is assigned to the maximum value, and then over ...
(The difference between 3 and 4 is that 3 requires a fixed-point n/2,n/2)
Source:
#include <iostream>using namespacestd;intmap[ -][ -],f[ -][ -];intMaxintAintb) { if(A>B)returnA; Else returnb;}intMain () {intN; Cin>>N; for(intI=1; i<=n; i++) for(intj=1; j<=i; J + +) Cin>>Map[i][j];intx, y; Cin>> x >>y; for(intI=1; i<=x; i++)if(i! = y) map[x][i]=-10000007; for(intI=1; i<=n; i++) for(intj=1; j<=i; J + +) F[i][j]=max (f[i-1][j],f[i-1][j-1])+Map[i][j];intcn1=0; for(intI=1; i<=n; i++)if(F[n][i]>ans) ans=F[n][i]; cout<<ans;return 0;}
Back | Digital triangle 3,4