转载请注明出处:

viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents

题目链接:http://poj.org/problem?id=1163

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

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

简单DP例如以下:

#include <iostream>
#include <cstring>
using namespace std; int n;
int dp[117][117];
void DP(int dp[117][117])
{
int i, j;
for(i = n-1; i >= 0; i--)
{
for(j = 1; j <= i; j++)
{
dp[i][j]+=max(dp[i+1][j],dp[i+1][j+1]);
}
}
}
int main()
{
int i, j;
while(cin >> n)
{
for(i = 1; i <= n; i++)
{
for(j = 1; j <= i; j++)
{
cin>>dp[i][j];
}
}
DP(dp);
cout<<dp[1][1]<<endl;
}
return 0;
}

poj1163The Triangle(简单DP)的更多相关文章

  1. POJ 1163 The Triangle 简单DP

    看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...

  2. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  4. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  5. 简单dp --- HDU1248寒冰王座

    题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...

  6. poj2385 简单DP

    J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  7. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

  8. poj 1157 LITTLE SHOP_简单dp

    题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...

  9. hdu 2471 简单DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=(  dp[n-1][m],dp[n][m-1],d[i][k ...

随机推荐

  1. 纠正一个概念:类就有VMT,各实例不过是共享这个VMT而已

    不是只有实例才有VMT,举个例子,各实例的VMT地址是相同的: Use System.Contnrs; procedure TForm1.BitBtn2Click(Sender: TObject); ...

  2. 基于Qt的类QQ气泡聊天的界面开发

    近期在写IM 聊天界面,想设计出一个类似QQ气泡聊天的样式 使用了几种办法 1:使用Qt以下的QListview来实现QQ类似效果.差强人意 2:使用QWebview载入html css样式来完毕.发 ...

  3. Codeforces Round #296 (Div. 2) A B C D

    A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...

  4. hdu 3309 Roll The Cube ( bfs )

    Roll The Cube Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. 属性“dataProvider”有多个初始值设定项。(注意:“dataProvider”是“mx.charts.BarChart”的默认属性)。

    1.错误描写叙述 属性"dataProvider"有多个初始值设定项.(注意:"dataProvider"是"mx.charts.BarChart&q ...

  6. poj - 1170 - Shopping Offers(减少国家dp)

    意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...

  7. [置顶] Guava学习之Immutable集合

    Immutable中文意思就是不可变.那为什么需要构建一个不可变的对象?原因有以下几点: 在并发程序中,使用Immutable既保证线程安全性,也大大增强了并发时的效率(跟并发锁方式相比).尤其当一个 ...

  8. Net Kafka

    Net Kafka Kafka 协议实现中的内存优化 Jusfr 2016-04-18 08:28 阅读:241 评论:1     Kafka API: TopicMetadata Jusfr 201 ...

  9. Codeforces Round #269 (Div. 2) A B C

    先说C 题目链接:http://codeforces.com/problemset/problem/471/C 题目意思:有 n 张卡,问能做成多少种不同楼层(floor)的 house.注意这 n ...

  10. Windows 10Bash命令

    Windows 10预览版14316开启Bash命令支持 00x0 前言 4月7日凌晨,微软推送了最新的Windows 10一周年更新预览版14316,其中重要的是原生支持Linux Bash命令行支 ...