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
  • 相关阅读:
    C#中在AxWebBrowser控件注入JS脚本的方法
    C# 操作鼠标移动到指定的屏幕位置方法
    uvm的sequence
    uvm学习杂记
    形参和实参
    gvim中对变量的识别
    验证环境中的program为什么必须是automatic
    FIFO设计验证经验谈
    AMBA总线基础知识简介
    systemverilog中module与program的区别
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3246131.html
Copyright © 2011-2022 走看看