POJ 3176 Cow Bowling (DP base)

Source: Internet
Author: User

Description

The Cows Don'T use actual bowling balls when they go bowling. They a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this:          7        3   8      8   1   0    2   7   4   4  4   5   2   6   5Then the other cows traverse the triangle starting fromIts tip and moving" Down"To one of the diagonally adjacent cows until the"Bottom"Row isReached. The cow'S score is the sum of the numbers of the cows visited along the. The cow with the highest score wins that frame. Given a triangle with N (1<= N <= -Rows, determine the highest possible sum achievable.

Input

12.. n+1: Line i+1 contains i space-separated integers that represent row I of the triangle.

Output

1 using the traversal rules

Sample Input

5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5

Sample Output

30

Hint

Explanation of the sample:            7         *        3   8       *      8   1   0       *    2    7   4   4       *  4    5   2   6   5   is as shown above.

Source

Usaco 2005 December Bronze
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 #defineN 3566 intMp[n][n];7 intDp[n][n];8 intMain ()9 {Ten     intN; One      while(SCANF ("%d", &n) = =1){ AMemset (DP,0,sizeof(DP)); -          for(intI=1; i<=n;i++){ -              for(intj=1; j<=i;j++){ thescanf"%d",&mp[i][j]); -             } -         } -dp[1][1]=mp[1][1]; +          for(intI=2; i<=n;i++){ -              for(intj=1; j<=i;j++){ +Dp[i][j]=max (dp[i-1][j-1]+mp[i][j],dp[i-1][j]+mp[i][j]); A             } at         } -         intmaxn=-1; -          for(intI=1; i<=n;i++){ -maxn=Max (maxn,dp[n][i]); -         } -printf"%d\n", MAXN); in     } -     return 0; to}
View Code

POJ 3176 Cow Bowling (DP base)

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.