zoukankan      html  css  js  c++  java
  • Cow Bowling

    Problem 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
     
    Source
    PKU
     
    ************************************************************************************************
    普通dp
    ************************************************************************************************
     1 #include<iostream>
     2 #include<string>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<cmath>
     7 using namespace std;
     8 int dp[359][359];
     9 int i,j,k,n;
    10 int map[359][359];
    11 int main()
    12 {
    13     cin>>n;
    14     for(i=1;i<=n;i++)
    15      for(j=1;j<=i;j++)
    16       cin>>map[i][j];
    17     for(i=1;i<=n;i++)
    18      dp[n][i]=map[n][i];
    19     for(i=n-1;i>=1;i--)
    20      for(j=1;j<=i;j++)
    21       {
    22           dp[i][j]=dp[i+1][j]+map[i][j];
    23           if(dp[i][j]<dp[i+1][j+1]+map[i][j])
    24             dp[i][j]=dp[i+1][j+1]+map[i][j];
    25 
    26       }
    27     cout<<dp[1][1]<<endl;
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    oracle 查询 主机名和对应的IP地址
    mysql 常用命令
    linux 下 mysql-5.5.8 安装
    oracle批量插入数据(测试)
    Oracle数据库查询优化(上百万级记录如何提高查询速度)
    针对分区表一个月3个分区定期清理脚本
    C语言中%p,%u,%lu都有什么用处
    MAC下查看环境变量的值的方法
    Mac 终端 Linux 命令总结(简单命令)
    TypeScript学习-TypeScript环境配置
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3246131.html
Copyright © 2011-2022 走看看