zoukankan      html  css  js  c++  java
  • Cow Bowling

    Problem Description
    The cows don't use actual bowling balls when they go bowling.  They each take 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   5
    Then the other cows traverse the triangle starting from its tip and moving "down" to one of the two diagonally adjacent cows until the "bottom" row is reached.  The cow's score is the sum of the numbers of the cows visited along the way. The cow with the highest score wins that frame.
    Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.
     
    Input
    Line 1: A single integer, N
    Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.
     
    Output
    Line 1: The largest sum achievable 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
     
    Source
    PKU
     
    ************************************************************************************************
    普通dp
    ************************************************************************************************
     1 #include<iostream>
     2 #include<string>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<cmath>
     7 using namespace std;
     8 int dp[359][359];
     9 int i,j,k,n;
    10 int map[359][359];
    11 int main()
    12 {
    13     cin>>n;
    14     for(i=1;i<=n;i++)
    15      for(j=1;j<=i;j++)
    16       cin>>map[i][j];
    17     for(i=1;i<=n;i++)
    18      dp[n][i]=map[n][i];
    19     for(i=n-1;i>=1;i--)
    20      for(j=1;j<=i;j++)
    21       {
    22           dp[i][j]=dp[i+1][j]+map[i][j];
    23           if(dp[i][j]<dp[i+1][j+1]+map[i][j])
    24             dp[i][j]=dp[i+1][j+1]+map[i][j];
    25 
    26       }
    27     cout<<dp[1][1]<<endl;
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    每日一题_191126
    每日一题_191125
    每日一题_191124
    每日一题_191123
    每日一题_191122
    每日一题_191121
    每日一题_191120
    由一元二次不等式的解法引出的自编题
    2019高考,李尚志教授三评“维纳斯”(来自网络)
    2019全国卷(III)理科23题的另类解法
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3246131.html
Copyright © 2011-2022 走看看