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 }
  • 相关阅读:
    RedHat5.8 编译内核驱动 合成initrd.img
    matrix-gui-2.0 将javascript文件夹改成js文件夹
    使用PHP配置文件
    Ubuntu 16.10 Apache PHP Server
    Ubuntu 16.10 中文环境 Shell输出英文提示
    制作SD卡img文件,并扩容
    Linux syslogd
    Windows cmd findstr
    jquery ztree异步搜索
    怎样在点击li时添加样式,移除兄弟样式
  • 原文地址:https://www.cnblogs.com/lueagle/p/6550074.html
Copyright © 2011-2022 走看看