nyoj--18--The Triangle(dp水题)
The Triangle
- 描述
-
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
-
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAX 210
int dp[MAX][MAX];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
scanf("%d",&dp[i][j]);
}
for(int i=n-1;i>=1;i--)
{
for(int j=1;j<=n;j++)
dp[i][j]+=max(dp[i+1][j],dp[i+1][j+1]);
}
printf("%d\n",dp[1][1]);
}
return 0;
}
nyoj--18--The Triangle(dp水题)的更多相关文章
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- NYOJ 18 The Triangle 填表法,普通dp
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=18 The Triangle 时间限制:1000 ms | 内存限制:6553 ...
- 13年山东省赛 The number of steps(概率dp水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud The number of steps Time Limit: 1 Sec Me ...
- hdu 1201:18岁生日(水题,闰年)
18岁生日 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- dp水题 序列问题 (9道)
9道题.A了8道,A题看题解也没弄懂怎么维护m段子序列的,过一段时间再回来看看 dp试水 47:56:23 125:00:00 Overview Problem Status Rank ( ...
- 【BZOJ】1270: [BeijingWc2008]雷涛的小猫(DP+水题)
http://www.lydsy.com/JudgeOnline/problem.php?id=1270 这完全是一眼题啊,但是n^2的时间挺感人.(n^2一下的级别请大神们赐教,我还没学多少dp优化 ...
- 学校作业-Usaco DP水题
好吧,因为USACO挂掉了,所以我写的所有代码都不保证正确性[好的,这么简单的题,再不写对,你就可以滚粗了! 第一题是USACO 2.2.2 ★Subset Sums 集合 对于从 1 到 N 的连 ...
随机推荐
- 使用记事本开发第一个java程序
记事本是开发java程序最基础的一个工具 第一步:编写 新建一个文件名为Hello的文本文档,并将文件扩展名改为.java. 在文本框内输入我们的程序代码 ——————————————我是分割线——— ...
- BZOJ3170: [Tjoi2013]松鼠聚会
[传送门:BZOJ3170] 简要题意: 给出n个点的坐标,规定两个点的距离=max(|x1-x2|,|y1-y2|) 要求选出一个点,使得这个点到所有点的距离和最小 题解: 切比雪夫转换例题 将一个 ...
- oracle性能检测sql语句
1. 监控事例的等待 select event,sum(decode(wait_Time,0,0,1)) "Prev",sum(decode(wait_Time,0,1,0)) & ...
- 基于Apache CXF的Web Service服务端/客户端
转自:https://www.aliyun.com/zixun/wenji/1263190.html CXF服务端: package com.sean.server; import javax.jws ...
- category与协议的不同
1,category是针对类进行扩展,而且该类必须有里面的所有成员 协议不同可以选择性实现 2,category是针对一个具体的类实现,其他类没有 协议允许任何类使用,只要实现以后只能通过重写修改 3 ...
- POJ 3252 组合数学?
大神们的题解我一个都没看懂........... 十分的尴尬 题意:算出闭区间内二进制中0的个数大于等于1的个数的数字有多少个 思路: 组合数学(n小于500的时候都可以出解,只不过高精比较麻烦). ...
- 将百度百科的机器学习词条中的一段关于机器学习的demo改用Java写了一遍
这是引用的百度百科中关于机器学习的一段示例,讲述了通过环境影响来进行学习的例子. 下面是代码: import java.io.BufferedReader; import java.io.IOExce ...
- DirectUI界面编程(三)从XML文件中加载界面
Duilib支持xml界面布局,使得界面设计与逻辑处理相分离,本节介绍如何从xml文件中加载界面元素. 我们需要以下几个步骤: 创建并初始化CPaintManagerUI对象. 创建CDialogBu ...
- [oracle] 组织架构退格显示 connect by
1. 按组织架构关系退格显示 create or replace view v_vieworg asselect --v.OBJID,v.OBJNAMElevel as levelid, lpad(' ...
- 常用sql调优《一》
1. 使用索引,避免在索引列上使用计算. 2.用>=替代> <=替代< 3.用UNION替换OR (适用于索引列) 4.用IN来替换OR 或者 用EXISTS替代IN 5 用W ...