• 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 }
  • 相关阅读:
    Linux03__管理
    Linux02__常用命令
    Linux01__系统安装
    爬虫性能相关
    【转载】资源整合
    Continuous integration
    行业巨头的云计算冷数据存储应用和比较 2016-07-15
    win7中使用docker ——配置阿里云容器加速
    layui treeSelect插件的使用
    springboot 拦截器设置
  • 原文地址:https://www.cnblogs.com/lueagle/p/6550074.html
Copyright © 2020-2023  润新知