经典的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. 常用数据字典---bai

    --常用数据字典 -- system: normal; sysdba --查询所有的逻辑对象.所有. select count(1) from dba_objects; select * from d ...

  2. java常见内存溢出(OOM)

    jvm内存区域 程序计数器一块很小的内存空间,作用是当前线程所执行的字节码的行号指示器. java栈与程序计数器一样,java栈(虚拟机栈)也是线程私有的,其生命周期与线程相同.通常存放基本数据类型, ...

  3. HDU4525+公式

    一开始TLE了... /* 模拟 */ #include<stdio.h> #include<math.h> ; typedef __int64 int64; int64 a[ ...

  4. configure脚本参数介绍

    configure脚本有大量的命令行选项. 下面对每一个选项进行简略的介绍: --cache-file=FILE'configure' 会在你的系统上测试存在的特性(或者bug!).为了加速随后进行的 ...

  5. Java集合ArrayList的应用

    /** * * @author Administrator * 功能:Java集合类ArrayList的使用 */ package com.test; import java.io.BufferedR ...

  6. ANDROID_MARS学习笔记_S01原始版_016_Service

    一.代码1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayo ...

  7. Android 使控件各占屏幕的一半

    在xml中将两个要占屏幕一半的控件都加上android:layout_weight="1": 注意:weight只能用在LinearLayout布局中. 在LinearLayout ...

  8. dojo.hitch 原理

    在使用dojo的时候,遇到dojo.hitch这个函数 ,官方文档说的很清楚,将函数和作用域绑定起来,这让我想起了call和apply这两个函数,call和apply用于改变一个方法的执行上下文,JS ...

  9. spring-boot启动debug信息中non-fatal error解决

    java.lang.ClassNotFoundException: org.springframework.data.web.config.EnableSpringDataWebSupport添加依赖 ...

  10. hdu1501Zipper(记忆化搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1501 搜了下记忆化搜索是嘛 然后就看到这个题了 不过一不小心看到代码了 代码又那么短 一不小心给记住了 然后看了 ...