题目链接:

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. p2p登录拦截

    1.编写拦截标签 package com.xmg.p2p.base.util; import java.lang.annotation.ElementType; import java.lang.an ...

  2. Dynamics 365Online 查询Web Api的请求WebUri

    在on-premises版本中,获取weburi的方式是进设置-自定义项-开发人员资源中查看地址,但online版本中的地址会有些许的差异 online的开发者资源中的地址如下图,如果你在页面java ...

  3. C#+SharpMap的相关代码

    //放大的代码: private void MapZoomIn(NameValueCollection queryString) { SharpMap.Map map = Session[" ...

  4. Ubuntu 添加删除用户 How to Add and Delete Users on Ubuntu 16.04

      Introduction One of the most basic tasks that you should know how to do on a fresh Linux server is ...

  5. Visualizing MNIST with t-SNE, MDS, Sammon’s Mapping and Nearest neighbor graph

    MNIST 可视化 Visualizing MNIST: An Exploration of Dimensionality Reduction At some fundamental level, n ...

  6. 关系型数据库基本概念及MySQL简述

    数据库基本概念">关系型数据库基本概念 数据库: 对大量信息进行管理的高效解决方案. 按照数据结构来组织.存储和管理数据的库. 数据库系统(DBS,DATABASE SYSTEM): ...

  7. web 学习资源

    学习 https://skills.bugbank.cn/ https://github.com/JnuSimba/MiscSecNotes 靶场 http://skysec.top/2018/01/ ...

  8. Redis搜索引擎设计

    以下图片是基于自身对知识掌握的基本能力而画出的,并没有系统全面的读过活跃于互联网大牛的著作(个人认为那样会限制自身的思维空间),因此,若图片里存在错误,敬请批评指正,谢谢! 除非互联网项目,传统的制造 ...

  9. 在html的JavaScript部分计算,保留小数点后面的位数

    例: f_pbf = ((f_boday_fat/f_weight)*100).toFixed(1);      注:例子中的.toFixed(1)是所用函数,确保在所得结果中保留小数点后面一位数,若 ...

  10. SweetAlert插件 弹框插件

    sweetalert是一个漂亮的弹窗 中文网址: http://mishengqiang.com/sweetalert/ 它需要2个文件:sweetalert-dev.js和sweetalert.cs ...