Back | Digital triangle 3,4

Source: Internet
Author: User

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&GT;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

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.