转载请注明出处:

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. Win8下在Vmware11中安装使用苹果系统OS X 10.10

    原文:Win8下在Vmware11中安装使用苹果系统OS X 10.10   近来因为需要做 iOS 的项目,所以需要多花一些时间看看敲敲代码.因为自己手头上并没有 Mac(过年为了闲的时候能玩玩游戏 ...

  2. [Cocos2d-x]解决Android平台ndk-build时不自动删除外部库

    参考链接: http://blog.chinaunix.net/uid-26009923-id-3430612.html http://hi.baidu.com/hpyfei/item/52a2b21 ...

  3. Android中特殊图形的生成样例

    import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; impor ...

  4. RIA Test:try catch 对 Error #1009 (无法访问空对象引用的属性或方法)的处理

    功能: 实现登录账户的强制登录, 用If 判断当前账户是否可用.若可用,则跳出if体直接登录,若不可用,则进入If体点击 “强制登录” 按钮. 问题:如果不可用,则if 条件中的对象不可见,这样程序会 ...

  5. VB.NET 机房收费系统项目总结

    VB.NET机房收费系统项目总结 从2013年5月3日——2013年8月20日历时三个多月的.NET机房收费系统终于完成了.项目做完了,真有一种如释重负的感觉. 下面我将从文档.UML图,代码这三个方 ...

  6. nyist oj 311 全然背包 (动态规划经典题)

    全然背包 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描写叙述 直接说题意,全然背包定义有N种物品和一个容量为V的背包.每种物品都有无限件可用.第i种物品的体积是c,价值是 ...

  7. [置顶] ANDROID 返回,菜单和HOME键的监听

    ------网上找了很多资料,项目中使用,最后将经验总结如下: 1,返回和菜单键是可以直接重写onKeyDown(int keyCode, KeyEvent event) 方法监听: @Overrid ...

  8. debian下使用siege进行压力测试

    一:siege siege是开源的一个测试工具,可以对指定文本的URL列表进行负载测试,也可以在执行其他请求前让某个请求休眠,从而让你感觉某个用户在转移到web应用的下一个文档前正在读取该文档. ht ...

  9. hdu2569(递推dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2569 分析: f(n),n个珠子的合格数:a(n),n个珠子,最后2个相同的合格数:b(n),n个珠子 ...

  10. Unity3d之MiniJson与LitJson之间的较量

    由于项目不得不用到json来解析服务器端传来的数据,于是不得不选择一种在unity3d上面可用的json.开始根据网上推荐LitJson,于是下载下来源码,导入项目: 经过测试可以用:但是移植到ipa ...