The Triangle
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 41169   Accepted: 24882

Description

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. 

Input

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 rows in the triangle is > 1 but <= 100. The numbers in the triangle,
all integers, are between 0 and 99.

Output

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

Sample Input

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

Sample Output

30

Source




    题意:求走过这个三角形时的最大数值。起点为第一行的唯一的那一个数,终点是第n行的某一个数。当中要走dp[i][j]的话。他的上一步仅仅能是dp[i-1][j-1]或者dp[i-1][j];



#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> #define inf 9999
#define INF -9999 using namespace std; int n;
int dp[361][361]; int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
scanf("%d",&dp[i][j]);
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
dp[i][j] += max(dp[i-1][j-1],dp[i-1][j]);
}
}
int maxx = 0;
for(int i=1;i<=n;i++)
{
if(maxx<dp[n][i])
{
maxx = dp[n][i];
}
}
printf("%d\n",maxx);
}
return 0;
}

POJ 1163&amp;&amp; 3176 The Triangle(DP)的更多相关文章

  1. POJ 2193 Lenny's Lucky Lotto Lists (DP)

    题目链接 题意 : 给你两个数N和M,让你从1到M中找N个数组成一个序列,这个序列需要满足的条件是后一个数要大于前一个数的两倍,问这样的序列有多少,输出. 思路 : dp[i][j]代表着长度为 i ...

  2. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  7. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  8. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  9. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

随机推荐

  1. 2017 icpc 西安网络赛

    F. Trig Function 样例输入 2 0 2 1 2 2 样例输出 998244352 0 2 找啊找啊找数列和论文.cosnx可以用切比雪夫多项式弄成(cosx)的多项式,然后去找到了相关 ...

  2. [NOIp2017提高组]宝藏

    #include<cstdio> #include<cctype> #include<algorithm> inline int getint() { regist ...

  3. Java 导出大批量数据excel(百万级)(转载)

    参考资料:http://bbs.51cto.com/thread-1074293-1-1.html                 http://bbs.51cto.com/viewthread.ph ...

  4. [漏洞检测]Proxpy Web Scan设计与实现(未完待续)

    Proxpy Web Scan设计与实现 1.简介:          Proxpy Web Scan是基于开源的python漏洞扫描框架wapiti改造的web漏洞扫描器,其主要解决以下几个问题而生 ...

  5. 按树型显示BOM的结构

    在制造企业中,生产的每一个产品都由一道或多道工序组成,在组成成品之前,每一道工序经由物料--物料组成半成品,或物料--半成品组成新的半成品,亦或由半成品--半成品组成新的半成品.复杂的成品经由多道工序 ...

  6. Kafka的架构设计(目前翻译最好的一稿)

    转自:http://www.oschina.net/translate/kafka-design 参与翻译(4人):fbm, 飞翔的猴子, Khiyuan, nesteaa 感谢这些同志们的辛勤工作, ...

  7. IIS 服务器隐藏index.php 的方法

    在项目根目录下创建web.config文件  写入以下代码即可 <?xml version="1.0" encoding="UTF-8"?> < ...

  8. SQL通过身份证获取信息

    SELECT t.identity_number '身份证号',SUBSTR(t.identity_number,1,2) AS "省份",SUBSTR(t.identity_nu ...

  9. SQL Server 2005/2008备份数据库时提示“无法打开备份设备”

    错误描述: 今天备份sqlserver 2008数据库时候,想要将备份文件放在f盘的根目录下,结果提示如下信息:备份对于服务器“服务器名”失败.(Microsoft.SqlServer.Smo)其他信 ...

  10. global constructor

    HQ在要求我们修改code style后,又让我检查并去掉"global constructor". 第一次听说这玩意,就研究了一下.发现网上有人讨论的很精彩,就记下来. “glo ...