POJ1163 The Triangle
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 44997 | Accepted: 27174 |
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 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.
Input
Output
Sample Input
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output
30
Source
入门水题233
/**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[][];
int n;
int main(){
scanf("%d",&n);
int i,j;
for(i=;i<=n;i++)
for(j=;j<=i;j++)
scanf("%d",&a[i][j]);
for(i=n-;i;i--)
for(j=;j<=i;j++){
a[i][j]+=max(a[i+][j],a[i+][j+]);
}
printf("%d\n",a[][]);
return ;
}
POJ1163 The Triangle的更多相关文章
- 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 ...
- POJ1163 The Triangle 【DP】
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36918 Accepted: 22117 De ...
- (数字三角形)POJ1163 The Triangle
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 59698 Accepted: 35792 De ...
- 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 ...
- 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 ...
- POJ1163 The Triangle: 倒三角形问题
经典的DP问题,DP思想也很直接: 直接贴代码: #include<iostream> #include<cstdio> #include<algorithm> # ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
随机推荐
- U盘装机记录
U盘装机记录 1. 将U盘制作为启动盘(安装PE文件到U盘). (1)准备材料 8G以上U盘一个 一个可信的启动盘制作工具(这里是用的老毛桃) (2)将U盘插入电脑,单击老毛桃客户端(出现如下图所示的 ...
- 解答室内定位技术新方向:蓝牙AoA定位,值得了解 ——概念了解
转载搜狐 室内定位一直被炒的非常火的黑科技,也是近年资本追逐的热点,市场上一直有众多宣称可以做到厘米级,米级精度定位的公司,但问题很多,无法大规模商用.近些年有很多人尝试使用蓝牙beacon方式做定位 ...
- C语言进阶——注释符号12
注释可能大认为非常简单,但是注释其实在C语言中很关键,来看下面一段对话. ---学生: 老师,我觉得注释没有必要深究,因为很简单,对程序功能也没有影响. ---老师: 注释是C语言最重要的工具,我们先 ...
- ABAP CDS - SELECT, WHERE
格式 ... WHERE cond_expr ... 结果 定义CDS视图结果集的Where条件.访问CDS视图时,结果集仅包含来自数据源数据源的数据,该数据源数据源满足在where之后指定的条件co ...
- MySQL忘记密码怎么重置
1打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 输入命令 mysqld --skip-grant-tables 回车,此时就跳过了mysql的用户验证.注意输入此命令之后 ...
- Mysql处理海量数据时的一些优化查询速度方法【转】
最近一段时间由于工作需要,开始关注针对Mysql数据库的select查询语句的相关优化方法.由于在参与的实际项目中发现当mysql表的数据量达到百万级时,普通SQL查询效率呈直线下降,而且如果wher ...
- 20145202课后题,2.56&9.16
我做的是2.56题,要求我用多组值来测试show_bytes 9.16 主要是对局部性进行了一些分析. 实验楼里面是空的,我电脑上显示不出来,所以我就做了一些书上的习题. 第十章的所有题目都被学长做过 ...
- 内置函数--sorted,filter,map
sorted() 排序函数. 语法: sorted(Iterable, key=None, reverse=False) Iterable: 可迭代对象; key: 排序规则(排序函数); reve ...
- Hbase的安装与部署(集群版)
HBase 部署与使用 部署 Zookeeper 正常部署 $ ~/modules/zookeeper-3.4.5/bin/zkServer.sh start 首先保证 Zookeeper 集群的正常 ...
- gVim的 设置
在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:set ts=4 (注:ts是tabstop的缩写,设TAB宽4个空格)set expandtab TAB替换为空格::set ...