1163:The Triangle

  • 查看
  • 提交
  • 统计
  • 提问

时间限制:

1000ms

内存限制:

65536kB

描述

7
3   8
8   1   0
2   7   4   4
4   5   2   6   5

(Figure 1)

Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.

输入

Your program is to read from standard input. The first line contains one integer N: the number of rows in the triangle. The following N lines describe the data of the triangle. The number of rowsin the triangle is > 1 but <= 100. The numbers in the triangle, all integers, are between 0 and 99.

输出

Your program is to write to standard output. The highest sum is written as an integer.

样例输入

5

7

3 8

8 1 0

2 7 4 4

4 5 2 6 5

样例输出

30

  • 查看
  • 提交
  • 统计
  • 提问

#include"iostream"
using namespace std;
int max(int x,int y)
{
 if(x>y)
  return x;
 else
  return y;
}
int main()
{
 int row;
 cin>>row;
 int** matrix=new int*[row+1];
 for(int i=0;i<row+1;i++)
  matrix[i]=new int[row+1];
 for(int i=1;i<=row;i++)
  for(int j=1;j<=i;j++)
   cin>>matrix[i][j];
 for(int i=row-1;i>=1;i--)
  for(int j=1;j<=i;j++)
  {
   matrix[i][j]+=max(matrix[i+1][j],matrix[i+1][j+1]);
  }
  cout<<matrix[1][1]<<endl;
}

转载于:https://www.cnblogs.com/lzhitian/archive/2011/08/16/2140076.html

POJ-1163(DP,Water)相关推荐

  1. poj 1163经典DP

    DP(Dinamic Programming),即为动态规划.     应该来说DP算法在ACM中是比较常见,也是比较难的,当然,做多了就不觉得难了,这是一条亘古不变的自然规律.以前在做ACM题的时候 ...

  2. poj 1205 :Water Treatment Plants (DP+高精度)

    题意:有n个城市,它们由一个污水处理系统连接着,每个城市可以选择 1.将左边城市过来的污水和右边城市过来的污水连同本身的污水排到河里  >V< 2.将左边来的污水连同自己的污水排到右边   ...

  3. OpenJudge/Poj 1163 The Triangle

    1.链接地址: http://bailian.openjudge.cn/practice/1163 http://poj.org/problem?id=1163 2.题目: 总时间限制: 1000ms ...

  4. POJ 3017 DP + 单调队列 + 堆

    题意:给你一个长度为n的数列,你需要把这个数列分成几段,每段的和不超过m,问各段的最大值之和的最小值是多少? 思路:dp方程如下:设dp[i]为把前i个数分成合法的若干段最大值的最小值是多少.dp转移 ...

  5. POJ 1159 (DP)

    题目:http://poj.org/problem?id=1159 思路: 找出原串的最长回文子串,当然这里说的回文子串可以不连续.用原串的长度减去最长回文子串的长度即可得出结果. 设原串a[5001 ...

  6. POJ 1037 DP

    题目链接: http://poj.org/problem?id=1037 分析: 很有分量的一道DP题!!! (参考于:http://blog.csdn.net/sj13051180/article/ ...

  7. POJ 1661 DP

    Help Jimmy Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11071   Accepted: 3607 Descr ...

  8. POJ 3666 dp

    题意 传送门 POJ 3666 基本思路是对 N 个位置枚举所有可能高度,并 dp 求最大值.可能高度取 N 个位置的高度即可,排序以方便顺序 dp.对于升序的情况 dp[i][j]=max{dp[i ...

  9. POJ 3666(DP)

    题目链接:http://poj.org/problem?id=3666 题目大意:给一个串,要求修改最少使得串满足非递增或非递减 题目思路:刚开始没想到,后来经学长提醒如果串里的数字变1000可以怎么 ...

  10. POJ 3257 DP

    题意: 思路: 用vector存上本出发点能到的地方&成本&有趣指数(用结构体保存) 然后DP就好了 f[i][j]表示到了i 成本为j的有趣指数最大是多少 f[vec[i][k].e ...

最新文章

  1. Redis实战(2)安装和试用
  2. c++缓冲区buffer
  3. python自增_Python的自增运算与Python变量的浅析
  4. Expression Blend实例中文教程(12) - 样式和模板快速入门Style,Template
  5. 自托管websocket和webapi部署云服务器域名及远程访问
  6. vs2012 设置默认的 include 目录
  7. miui12怎么自定义开机动画_小米MIUI 12凭什么敢向苹果iOS发起挑战
  8. Git命令之查看及设置用户名邮箱
  9. python3 荣誉证书(奖状)批量打印
  10. MyEclipse 10破解教程
  11. Unity Shader案例之——阴阳师画符效果
  12. Lua调试:getinfo详解
  13. Zookeeper分布式锁解决羊群效应的方案
  14. Learning Continuous Image Representation with Local Implicit Image Function解读
  15. 手机电池校正代码_安卓手机电量怎样校正?电池校正电量方法
  16. .ps1 is not digitally signed. The script will not execute on the system.
  17. app2sd使用教程
  18. 脑机接口(BCI)常用的实验范式
  19. 有关日期的一些工具类收集
  20. 实现EasyExcel对Excel读操作(读操作)

热门文章

  1. 传感器市场需求大幅提升 中企能否满足?
  2. graphicsmagick常用命令
  3. LintCode2016年8月8日算法比赛----子树
  4. OpenCart 2.x 系统商品数量库存减少逻辑
  5. WCF Service Configuration Editor的使用
  6. 字体样式及其属性、文本外观属性
  7. 大数据分析的思路与流程
  8. c语言内部超链接,HTML5中文本元素超链接的属性
  9. uc浏览器手机模拟_UC、华为、OPPO等8款手机浏览器被重点集中整治!原因是.........
  10. oracle多列转换成树结构,如何将树“压缩”为Oracle中层次结构上的聚合数据?