POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163
The Triangle
Description 7 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 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.
Output Your program is to write to standard output. The highest sum is written as an integer.
Sample Input 5 Sample Output 30 Source |
[Submit] [Go Back] [Status] [Discuss]
简单的动态规划。。。
#include<stdio.h>
int main() { int a[][]; int n,i,j; scanf("%d",&n); 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]+=(a[i+][j]>a[i+][j+])?a[i+][j]:a[i+][j+]; printf("%d\n",a[][]); return ; } |
POJ 1163 The Triangle(简单动态规划)的更多相关文章
- 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 二.分析 动态规划入门题. 状态转移方程$$DP[i][j] = A[i][j] + max(DP[i-1][j], DP[i][j])$$ 三.AC代码 1 #i ...
- 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 ...
- OpenJudge/Poj 1163 The Triangle
1.链接地址: http://bailian.openjudge.cn/practice/1163 http://poj.org/problem?id=1163 2.题目: 总时间限制: 1000ms ...
- POJ 1163 The Triangle(经典问题教你彻底理解动归思想)
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38195 Accepted: 22946 De ...
- 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 calc ...
- 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 ...
随机推荐
- iOS block
主要内容: block基本声明格式 block访问区域变量 block代替代理 block基本声明格式: ^(传入的参数){具体代码}; 注: Block实体开头是"^",接着是由 ...
- java实现记住密码功能(利用cookie)
<br> <input type="text" id="userName" name="userName" value=& ...
- 将DataReader转换为DataTable
public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader) { ///定义DataTable Data ...
- 转 centos虚拟机环境的构建。
转自:http://www.cnblogs.com/xiaoluo501395377/archive/2013/03/31/CentOs.html 一.前言 作为一个想从事j2ee后台开发的程序猿,l ...
- Blender 之修改器代码分析
Blender的修改器(modifier)模块,默认界面右下块(Property)面板的扳手,分类(修改.生成.形变.模拟)列出所有的修改器.也可以空格键 ...
- ECMAScript 5
2009年12月,ECMAScript 5.02011年6月,ECMAscript 5.1版发布2015年6月,ECMAScript 6正式通过,成为国际标准ES6第一个版本 ES2015,发布于20 ...
- 友盟推送 .NET (C#) 服务端 SDK rest api 调用库
友盟推送 .NET SDK rest api 介绍 该版本是基于友盟推送2.3版本封装的,网上查询了下发现没有.NET版本的调用库,官方也没有封装.NET的版本,只有python.java.php版本 ...
- SVN基本指令
Svn使用: Versions: Cornerstone: 如果命令行不出来,可以设置commonsline Tools 命令行:svn heip 获取服务器端数据 svn checkout 远端ur ...
- Python OS模块常用函数说明
Python的标准库中的os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.即它允许一个程序在编写后不需要任何改动,也不会发生任何问题,就可以在Linux和Wi ...
- Java内存模型及性能优化
最近在做一个项目的性能优化,遇到好多以前没有关注过的性能问题,一头雾水,今天做个笔记,简单记录下JVM相关的参数设置. 一.JVM内存模型 首先介绍下Java程序具体执行的过程: Java源代码文件( ...