OpenJudge/Poj 1163 The Triangle
1.链接地址:
http://bailian.openjudge.cn/practice/1163
http://poj.org/problem?id=1163
2.题目:
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
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- 来源
- IOI 1994
3.思路:
DP
4.代码:
#include "stdio.h"
//#include "stdlib.h"
#define N 102
int a[N][N];
int main()
{
int count;
int i,j;
scanf("%d",&count);
for(i = ;i <count;i++)
{
for(j=;j<=i;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i = count -;i>=;i--)
{
for(j=;j<=i;j++)
{
a[i][j] += ((a[i+][j]>a[i+][j+])?a[i+][j]:a[i+][j+]);
}
}
printf("%d",a[][]);
//system("pause");
return ;
}
OpenJudge/Poj 1163 The Triangle的更多相关文章
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- poj 1163 The Triangle &poj 3176 Cow Bowling (dp)
id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...
- POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 49955 Accepted: 30177 De ...
- POJ 1163 The Triangle 简单DP
看题传送门门:http://poj.org/problem?id=1163 困死了....QAQ 普通做法,从下往上,可得状态转移方程为: dp[i][j]= a[i][j] + max (dp[i+ ...
- poj 1163 The Triangle
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43809 Accepted: 26430 De ...
- Poj 1163 The Triangle 之解题报告
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42232 Accepted: 25527 Description 7 3 ...
- poj 1163 The Triangle 搜索 难度:0
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37931 Accepted: 22779 De ...
- POJ 1163 The Triangle DP题解
寻找路径,动态规划法题解. 本题和Leetcode的triangle题目几乎相同一样的,本题要求的是找到最大路径和. 逆向思维.从底往上查找起就能够了. 由于从上往下能够扩展到非常多路径.而从下往上个 ...
- poj 1163 The Triangle 记忆化搜索
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44998 Accepted: 27175 De ...
随机推荐
- mybatis 打印sql log配置
mybatis 打印sql log, 方便调试.如何配置呢? log4j.xml : <!-- 打印sql start --> <appender name="IBatis ...
- NSDateFormatter 问题
NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; NSString *inputDateStr = @&quo ...
- android学习日记20--连接组件之Intent和IntentFilter
上次刚了解完Android的四大组件,现在学习组件间通信的Intent和IntentFilter 一.Intent 1.简述 Intent(意图)在应用程序运行时连接两个不同组件,是一种运行时的绑定机 ...
- 《Maven_孔浩》Maven介绍及安装
maven是apache基金会下的一个项目管理工具. 安装步骤 1.下载并解压 2.配置环境变量M2_HOME(解压后的目录):将M2_HOME\bin加入到PATH环境变量中 3.测试:在命令行输入 ...
- Understanding the Router
Understanding the Router Our module is coming along nicely. However, we're not really doing all that ...
- 心跳之旅—💗—iOS用手机摄像头检测心率(PPG)
[前情提要] 光阴似箭,日月如梭,最近几年,支持心率检测的设备愈发常见了,大家都在各种测空气测雪碧的,如火如荼,于是我也来凑一凑热闹.[0]这段时间,我完成了一个基于iOS的心率检测Demo,只要稳定 ...
- Android_AsyncTask_json
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- Hibernate学习笔记--------4.查询
一.Get/Load Get方法是立即检索,而load是延迟检索,他们都是根据主键进行查询.在<class>标签中,若把lazy属性改为false,load方法就会立即检索,class中的 ...
- 关于jQuery源码中(function(window,undefined){//dosomething()})(window)写法解释
一.首先是最常见的闭包 (Closure) 范式自执行函数的写法,这里用匿名函数封装(构造块级作用域),避免了匿名函数内部的代码与外部之间发生冲突(如使用了相同的变量名). (function() { ...
- JSON对象和string的相互转换
JSON.stringify(obj) 将JSON转为字符串. JSON.parse(string) 将字符串转为JSON格式.