zoukankan      html  css  js  c++  java
  • POJ 3176 Cow Bowling

    Cow Bowling
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 18561   Accepted: 12360

    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

    Hint

    Explanation of the sample:

              7
    
    *
    3 8
    *
    8 1 0
    *
    2 7 4 4
    *
    4 5 2 6 5
    The highest score is achievable by traversing the cows as shown above.
     
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <string>
     5 #include <string.h>
     6 #include <cmath>
     7 
     8 using namespace std;
     9 
    10 
    11 int main(){
    12     int N;
    13     cin>>N;
    14     int **way = new int*[N+1];
    15     for(int i = 0;i<N+1;++i){
    16         way[i] = new int[i+2];
    17     }
    18     for(int i = 1;i<N+1;++i){
    19         for(int j = 1;j<=i;++j){
    20             cin>>way[i][j];
    21         }
    22     }
    23     way[0][1] = 0;
    24     for(int i = 0;i<N+1;++i){
    25         way[i][0] = 0;
    26     }
    27     //dp
    28     for(int i = 1;i<N+1;++i){
    29         for(int j = 1;j<=i;++j){
    30             way[i][j] += max(way[i-1][j],way[i-1][j-1]);
    31         }
    32     }
    33 
    34     int max_weight = 0;
    35     for(int j = 1;j<=N;++j){
    36         if(way[N][j]>max_weight)max_weight = way[N][j];
    37     }
    38     cout<<max_weight<<endl;
    39 
    40     for(int i = 0;i<N+1;++i)delete way[i];
    41     delete way;
    42     return 0;
    43 }
  • 相关阅读:
    玩转----使用数据驱动ddt时,如何写测试报告2种方法
    玩转----svn--入门
    玩转----Selenium家族简介
    起名的含义
    重新开始
    学习django: 庄园漫步
    测试常用的表格
    【Kata Daily 190927】Counting sheep...(数绵羊)
    【Kata Daily 190924】Difference of Volumes of Cuboids(长方体的体积差)
    【Kata Daily 190923】Odder Than the Rest(找出奇数)
  • 原文地址:https://www.cnblogs.com/lueagle/p/6550074.html
Copyright © 2011-2022 走看看