经典的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. git fork同步原作者

    从github上获取源代码,一种是直接下载,但是无法改动后提交. 一种是fork一下,但是和原作者同步麻烦. 所以我找到了四个命令,解决同步问题. 以后建议大家fork一下,主要是哪天对源码熟悉了,想 ...

  2. hdu 5172 GTY's gay friends

    GTY's gay friends 题意:给n个数和m次查询:(1<n,m<1000,000);之后输入n个数值(1 <= ai <= n):问下面m次查询[L,R]中是否存在 ...

  3. 与wait for a undo record相关的系统卡死

    今天下班之前同事过来找我寻求帮助,说是某客户的ORACEL数据库服务器从昨天起就开始很奇怪,一个语句执行很慢很慢,好像整个系统都卡住了.      问题1:请问最近应用系统有更新过程序吗?答:没有更新 ...

  4. sencha touch

    download http://www.sencha.com/products/touch/thank-you/ Developer Center http://developer.sencha.co ...

  5. python 删除文件和文件夹

    1.删除文件 '''删除文件 ''' def DeleteFile(strFileName): fileName = unicode(strFileName, "utf8") if ...

  6. portlet初学习及HelloWorld例子

    1. 在myeclipse中新建一个web project,在src中新建如下类: package com.yoyo.portlet; import java.io.IOException; impo ...

  7. 安全测试常见的10个问题 ZT

    1, 问题:没有被验证的输入     测试方法:     数据类型(字符串,整型,实数,等)    允许的字符集    最小和最大的长度    是否允许空输入    参数是否是必须的    重复是否允 ...

  8. easyui源码翻译1.32--ComboGrid(数据表格下拉框)

    前言 扩展自$.fn.combo.defaults和$.fn.datagrid.defaults.使用$.fn.combogrid.defaults重写默认值对象.下载该插件翻译源码 数据表格下拉框结 ...

  9. USB Type-C 连接器规范推出之后,市场很多低质量线材容易损坏设备

    USB Type-C 连接器规范推出之后,已有不少行动装置产品使用,其中最知名的产品为 Apple MacBook,机身仅提供一组 Type-C 端口,同时兼具充电与数据传输之用.市面上第三方厂商也开 ...

  10. 167. Two Sum II - Input array is sorted

    题目: Given an array of integers that is already sorted in ascending order, find two numbers such that ...