题目链接:

http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=18

The Triangle

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述

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.

 
输入
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.
输出
Your program is to write to standard output. The highest sum is written as an integer.
样例输入
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
样例输出
30

分析:
dp[i][j]=f_max(dp[i+1][j],dp[i+1][j+1])+a[i][j]; 代码如下:
#include<bits/stdc++.h>
#define pai 3.1415926535898
using namespace std;
int f_max(int a,int b)
{
if(a>b)
{
return a;
}else
{
return b;
}
}
int main()
{
int n;
scanf("%d",&n);
int a[n][n];
memset(a,,sizeof(a));
for(int i=;i<n;i++)
{
for(int j=;j<=i;j++)
{
scanf("%d",&a[i][j]);
}
}
int dp[n][n];
memset(dp,,sizeof(dp));
for(int j=;j<n;j++)
{
dp[n-][j]=a[n-][j];
}
for(int i=n-;i>=;i--)
{
for(int j=;j<=i;j++)
{
dp[i][j]=f_max(dp[i+][j],dp[i+][j+])+a[i][j];
}
}
printf("%d\n",dp[][]);
return ;
}

NYOJ 18 The Triangle 填表法,普通dp的更多相关文章

  1. nyoj 18 The Triangle

    The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure ...

  2. NYOJ-171 聪明的kk 填表法 普通dp

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=171 聪明的kk 时间限制:1000 ms  |  内存限制:65535 KB 难 ...

  3. dp的刷表法和填表法

    dp的刷表法和填表法 参考: 动态规划刷表法 - acmer_xue的博客 - CSDN博客http://blog.csdn.net/qq_30241305/article/details/52198 ...

  4. dp填表法,刷表法

    填表法:利用上一状态推当前 刷表法:利用当前推关联,利用刷表法较为便捷,向上边界较容易处理,处理在本次循环中的影响

  5. nyoj 1091 还是01背包(超大数dp)

    nyoj 1091 还是01背包 描述 有n个重量和价值分别为 wi 和 vi 的物品,从这些物品中挑选总重量不超过W的物品,求所有挑选方案中价值总和的最大值 1 <= n <=40 1 ...

  6. 2018.08.18 NOIP模拟 game(数位dp)

    Game 题目背景 SOURCE:NOIP2015-SHY4 题目描述 Alice 和 Bob 正在玩一个游戏,两个人从 1 轮流开始报数,如果遇到 7 的倍数或者遇到的这个数的十进制表示中含 7 , ...

  7. NYOJ 石子合并(一)(区间DP)

    题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=737 题目大意: 有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆 ...

  8. 利用道格拉斯·普客法(DP法)压缩矢量多边形(C++)

    1.算法描述 经典的Douglas-Peucker算法(简称DP法)描述如下: (1)在曲线首尾两点A,B之间连接一条直线AB,该直线为曲线的弦: (2)得到曲线上离该直线段距离最大的点C,计算其与A ...

  9. nyoj 36-最长公共子序列 (动态规划,DP, LCS)

    36-最长公共子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:18 submit:38 题目描述: 咱们就不拐弯抹角了,如题,需要你做的就是写 ...

随机推荐

  1. PowerDesigner 常用配置修改

    PowerDesigner中Name与Code同步的问题 转自:http://blog.sina.com.cn/u/48932504010005t9 PowerDesigner中,但修改了某个字段的n ...

  2. 推荐一个 JavaScript 日期处理类库 Moment.js

    官网: http://momentjs.com/ 处理时间的展示,很方便. 安装 bower install moment --save # bower npm install moment --sa ...

  3. TYPE_SCROLL_INSENSITIVE is not compatible with CONCUR_UPDATABLE

    There are two options when setting ResultSet to be scrollable: TYPE_SCROLL_INSENSITIVE - The result ...

  4. Oracle存储过程简单实例

    转自 http://www.cnblogs.com/nicholas_f/articles/1526029.html /*不带任何参数存储过程(输出系统日期)*/create or replace p ...

  5. Phoenix介绍(持续更新)

    现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要记录Phoenix. phoenix,中文译为“凤凰”,很美的名字.Phoenix是 ...

  6. LeetCode题解之To Lower Case

    1.题目描述 2.分析 遍历字符串,使用C++ 的 标准库函数 isalpha() 判断字符是否为 字母,然后对其做 tolower() . 3.代码 string toLowerCase(strin ...

  7. Jquery异步 Deferred Object

    Deferred Object )); return dtd.promise();};//使用$.when()为普通操作添加回调函数 为多个操作指定回调函数//$.when(deferred, def ...

  8. Ad-hoc 查询以及动态SQL的罪恶[译]

    本文为翻译文章,原文地址:https://www.simple-talk.com/blogs/2009/08/03/stolen-pages-ad-hoc-queries-and-the-sins-o ...

  9. 12.2Data Guard新特性--使用DBMS_DBCOMP.DBCOMP数据比较

          Oracle Data Guard会主动对Hot数据(数据正被读取或修改)执行验证, 无论是primary还是standby,但对于那些Cold数据不会做任何检查和校验.所以在12.2版本 ...

  10. 如何让触摸事件穿透一个View

    如何让触摸事件穿透一个View 偶然间发现,如何屏蔽或者让触摸事件穿透一个view是一个很简单的事情. 现象: 源码: // // ViewController.m // UserInteractio ...