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 }
  • 相关阅读:
    php 删除文件夹下的所有文件
    IBM AppScan 安全扫描:加密会话(SSL)Cookie 中缺少 Secure 属性 处理办法
    Tomcat/weblogic session失效时间的几种设置方法
    truncate与delete的区别
    oninput,onpropertychange,onchange的用法和区别
    HttpSessionBindingListener和HttpSessionAttributeListener区别
    insert table 和create table as 区别
    慎用create table as select,一定要注意默认值的问题
    mysql in与or效率比较
    值域范围
  • 原文地址:https://www.cnblogs.com/lueagle/p/6550074.html
Copyright © 2011-2022 走看看