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 }
  • 相关阅读:
    Peewee中join三张及以上的表时只能获取一张表的数据
    Ubuntu18.04安装 NVIDIA显卡驱动+CUDA+cuDNN+Pytorch
    Kubernetes Deployment 并行重启Pod
    git config 配置用户名、邮箱
    Python __str__() 方法
    阅读-自律100天-SMART法则
    Jenkins 调用执行jmeter脚本,并直接生成html报告
    推荐一款开源的Diffy自动化测试框架(转)
    mysql binlog日志自动清理及手动删除
    大数据测试
  • 原文地址:https://www.cnblogs.com/lueagle/p/6550074.html
Copyright © 2011-2022 走看看