POJ 1163.The Triangle-动态规划
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 50122 | Accepted: 30285 |
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
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=+;
int main(){
int n,a[N][N];
while(~scanf("%d",&n)){
memset(a,,sizeof(a));
for(int i=;i<n;i++){
for(int j=;j<=i;j++)
scanf("%d",&a[i][j]);
}
for(int i=n-;i>=;i--){
for(int j=;j<=i;j++)
a[i][j]+=max(a[i+][j],a[i+][j+]);
}
printf("%d\n",a[][]);
}
return ;
}
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 【动态规划】
一.题目 The Triangle 二.分析 动态规划入门题. 状态转移方程$$DP[i][j] = A[i][j] + max(DP[i-1][j], DP[i][j])$$ 三.AC代码 1 #i ...
- 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 ...
- 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 ...
随机推荐
- 配合JAVA的AJAX使用
概要 Ajax是“Asynchronous JavaScript and XML”的简称,即异步的JavaScript和XML. readyState属性用来返回当前的请求状态,有五个可选值.分别是0 ...
- 【bzoj1001】[BeiJing2006]狼抓兔子 最小割+对偶图+最短路
题目描述 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...
- 【bzoj3262】陌上花开 CDQ分治+树状数组
题目描述 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当且仅当Sa&g ...
- [NOIP2018 TG D1T3]赛道修建
题目大意:$NOIP2018\;TG\;D1T3$ 题解:题目要求最短的赛道的长度最大,可以想达到二分答案,接着就是一个显然的树形$DP$. 发现对于一个点,它子树中若有两条链接起来比要求的答案大,一 ...
- recycleview的基础Adapter
.封装了一个基础的adapter.,用于recycleview的快捷使用有BaseAdapter,BaseViewHolder,PAdapter,MainActivity public abstrac ...
- bzoj 3771 Triple FFT 生成函数+容斥
Triple Time Limit: 20 Sec Memory Limit: 64 MBSubmit: 847 Solved: 482[Submit][Status][Discuss] Desc ...
- gitlab迁移升级
一.迁移步骤 1.首先安装最新版本gitlab(gitlab7.2安装) 2.停止旧版本gitlab服务 3.将旧的项目文件完整导入新的gitlab bundle exec rake gitlab:i ...
- Document base D:\devTools\apache-tomcat-6.0.51\webapps\AppService does not exist or is not a readable directory
tomcat通过eclipse发布项目到webapp后 手动删除在webapp目录下的文件,启动tomcat时,会报出异常找不到那个删除的项目. 解决方法是(1)重新发布项目到webapp (2)在 ...
- 浏览器 连不上网 (3):DNS 服务器问题
解决:设置一下DNS服务器的地址 步骤: 打开网络和共享中心(网络和 Internet设置)-> 更改适配器 -> 双击我们连接的 无线网(WiFi式) 或 以太网(网线式): 从出现的窗 ...
- Spring 中 AbstractExcelView 支持根据模板生成Excel文件. 通过设置 view 的 URL 属性指定模板的路径
注意:1. 模板需放在 WEB-INF 目录下2. 指定模板路径时不需要添加扩展名, Spring将自动添加 .xls 到URL 属性中.3. 在指定URL前需先设置 view 的 Applicat ...