poj1163The Triangle(简单DP)
转载请注明出处: 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
all integers, are between 0 and 99.
Output
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)的更多相关文章
- POJ 1163 The Triangle 简单DP
看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- 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 ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
- 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 ...
随机推荐
- LCA 最近公共祖先 tarjan离线 总结 结合3个例题
在网上找了一些对tarjan算法解释较好的文章 并加入了自己的理解 LCA(Least Common Ancestor),顾名思义,是指在一棵树中,距离两个点最近的两者的公共节点.也就是说,在两个点通 ...
- linux下自助获取帮助
几乎所有命令都可以用 -h 或者--help参数 获取命令的使用方法帮助 man ls 也可以获取ls命令的详细帮助信息 man -k XXX 可以查看包含关键字XXX的文档 还有一个更详细的命 ...
- JavaScript引用类型之Object类
ECMAScript中的Object类跟Java中的Object类相似,ECMAScript中的全部类都由这个类继承而来,Object类中的全部属性和方法都会出如今其他类中,所以理解Object类,就 ...
- Wi-Fi万能钥匙:说是破解,其实有危险(转)
Wi-Fi 万能钥匙如此危险,怎样做才能让这种可能严重侵害公众利益的 app 在中国消失? 这个“钥匙”为什么能够破解 Wi-Fi?它真的是“破解” Wi-Fi 吗?两年前我就有这个疑问了,原谅我对一 ...
- 一种单片机支持WiFi的应用——SimpleWiFi在单片机中的应用
一种单片机支持WiFi的应用——SimpleWiFi在单片机中的应用 先上图: 现在的智能控制都是基于微控制器,随着智能的手持终端的普及,基于智能终端的控制就会越来越普遍. WIFI便是其中的一种.W ...
- Powershell Mail module, 发送outbox 里的全部邮件(一个.csv文件代表一封邮件)
把creating mail代码写到调用处,往outbox写入 mailxxx.csv文件,入面记录了邮件的主要内容 写入 #template $TMP = IMPORT-CSV "$($d ...
- Windows下visual studio code搭建golang开发环境
Windows下visual studio code搭建golang开发环境 序幕 其实环境搭建没什么难的,但是遇到一些问题,主要是有些网站资源访问不了(如:golang.org),导致一些包无法安装 ...
- Linq 数据操作,两个数组求差、交集、并集
int[] a = { 1, 2, 3, 4, 5, 6, 7 }; int[] b = { 4, 5, 6, 7, 8, 9, 10 }; int[] c = { 1, 2, 3, 3, 4, 1, ...
- SWT中的Tree中 添加右键弹出菜单
先看一下效果: 如图:在树上单击鼠标右键会弹出 弹出式菜单.做法其实很简单,先做一个树: final TreeViewer treeViewer = new TreeViewer(group, SWT ...
- ORA-16525: the Data Guard broker is not yet available
DGMGRL> disable configuration;ORA-16525: the Data Guard broker is not yet available Configuration ...