经典的DP问题,DP思想也很直接:

直接贴代码:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int max_size=;
int n, a[max_size][max_size];
int f[][max_size];
void initiate(){
memset(a,-,sizeof(a));
memset(f,,sizeof(f));
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
scanf("%d",&a[i][j]);
}
}
}
void solve(){
int pt_row=n;
for(int column=;column<=n;column++){
f[pt_row%][column]=a[pt_row][column];
}
for(int row=n-;row>=;row--){
for(int pt_col=;pt_col<=row;pt_col++){
f[(pt_row-)%][pt_col]=a[pt_row-][pt_col]+max(
f[pt_row%][pt_col],
f[pt_row%][pt_col+]
);
}
--pt_row;
}
printf("%d\n",f[pt_row%][]);
}
int main(){
while(scanf("%d",&n)!=EOF){
initiate();
solve();
}
return ;
}

POJ1163 The Triangle: 倒三角形问题的更多相关文章

  1. POJ1163——The Triangle

    Description 73 88 1 02 7 4 44 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program t ...

  2. POJ1163 The Triangle 【DP】

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36918   Accepted: 22117 De ...

  3. (数字三角形)POJ1163 The Triangle

    The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59698   Accepted: 35792 De ...

  4. POJ1163 The Triangle

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44997   Accepted: 27174 Description 73 ...

  5. Poj1163 The Triangle(动态规划求最大权值的路径)

    一.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 pro ...

  6. poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)

    经典的数塔模型. 动态转移方程:  dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+p[i][j]; #include <iostream> #include ...

  7. 【HDOJ】1362 The Bermuda Triangle

    1. 题目描述给定几个三角形拼成一个百慕大三角形. 2. 基本思路基本思路肯定是搜索,关键点是剪枝.(1) 若存在长度为$l$的边,则一定可以拼成长度为$k \cdot l$的三角形,则可拼成长度为$ ...

  8. [C++]2-3 倒三角形

    /* 倒三角形(Triangle) 输入正整数n<=20,输出一个n层的倒等腰三角形. 0 ######### 9 = 2* n-1 1 ####### 7 = 2*(n-1)-1 2 #### ...

  9. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

随机推荐

  1. hdu 2222 Keywords Search ac自动机入门

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:有N(N <= 10000)个长度不超过50的模式串和一个长度不超过1e6的文本串. ...

  2. 【filter】springmvc web.xml

    1.filter用于拦截用户请求,在服务器作出响应前,可以在拦截后修改request和response,这样实现很多开发者想得到的功能. 2.filter实现 ×编写一个继承Filter接口的类 ×在 ...

  3. Js template engine

    P http://www.jquery4u.com/javascript/10-javascript-jquery-templates-engines/ http://www.creativebloq ...

  4. gradient css

    <!DOCTYPE html> <html> <head> <title></title> <script src="js/ ...

  5. 使用js为html元素动态添加class

    <ul id="root"> <li>1</li> <li>2</li> <li>3</li> ...

  6. 关于 IIS 上的 Speech 设置

    在之前的开发过程中,发现在 微软各个版本的Speech中(从sdk5.1 到 最新的 Speech PlatFarme V11),在本地可以生成音频文件,但是在IIS上却生成无法生成完整的文件. 调试 ...

  7. sjtu1333 函数时代

    Description Taring说:生活的过程就是执行函数的过程.需要命令,也需要回报.更重要的,是得到回报的过程. 好吧...这道题其实和上面的也没啥关系TAT,我们要求的是下面的问题: 给定\ ...

  8. about mobile web

    http://blog.csdn.net/kavensu/article/details/8722268 http://cavenfeng.iteye.com/blog/1551516 http:// ...

  9. unity 引入 ios 第三方sdk

    原地址:http://blog.csdn.net/u012085988/article/details/17785023 unity开发中ios应用时,要想成功引入第三方sdk,首先得知道c#与obj ...

  10. 对 APM 用户的一次真实调查分析(上)

    一.前言 国内的 APM 行业这两年刚刚起步,但是在国外却比较成熟了,并且由于这两年人力成本的快速提高,国内外涌现了几家非常不错的 APM 企业,例如,OneAPM,APPdynamic,Dynami ...