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 ...
随机推荐
- Android设计模式—策略模式
1.策略模式概念 定义一系列算法,把他们独立封装起来,并且这些算法之间可以相互替换.策略模式主要是管理一堆有共性的算法,客户端可以根据需要,很快切换这些算法,并且保持可扩展性. 策略模式的本质:分离算 ...
- CentOS 6.5 下载地址
CentOS 6.5 主要改动 Precision Time Protocol(精确时间协议)—— 原先是项技术预览 —— 现在已获全面支持.以下驱动程序支持网络时间戳印:bnx2x.tg3.e100 ...
- TFS上使用Beyond Compare来比较源码
In Visual Studio, go to the Tools menu, select Options, expand Source Control, (In a TFS environment ...
- 逻辑网络(Logical Network)
Introduction The VMM documentation indicates that “A logical network is used to organize and simplif ...
- thinPHP中多维数组的遍历
$drug=array( 'ACEI'=>array(array('ch_name'=>'卡托普利','en_name'=>'captopril'),array('ch_nam ...
- 实现android activity之间的跳转
android程序一般不会只有一个activity,会碰到activity之间的跳转.以下是使用Intent做应用程序内部的activity做跳转.比如,应用程序第一个activity是: 点击“下一 ...
- Python 将文本转换成html的简单示例
实例txt文件test_input.txt: Welcome to World Wide Spam. Inc. These are the corporate web pages of *World ...
- css Hack,用IE11模拟测试的,条件注释要找真IE去测,模拟的无效
<!DOCTYPE html> <!--[if lt IE 7 ]> <html class="ie6 ie"> <![endif]--& ...
- mysql使用心得
SET FOREIGN_KEY_CHECKS=0; -- ------------------------------ Table structure for `staff`-- ---------- ...
- mysql中不同事务隔离级别下数据的显示效果--转载
事务是一组原子性的SQL查询语句,也可以被看做一个工作单元.如果数据库引擎能够成功地对数据库应用所有的查询语句,它就会执行所有查询,如果任何一条查询语句因为崩溃或其他原因而无法执行,那么所有的语句就都 ...