数字三角形

Time Limit: 1 Sec  Memory Limit: 162 MB

题目连接

http://www.tyvj.cn/p/1044

Description

示出了一个数字三角形。 请编一个程序计算从顶至底的某处的一条路
径,使该路径所经过的数字的总和最大。
  每一步可沿左斜线向下或右斜线向下走;
  1<三角形行数<25;
  三角形中的数字为整数<1000;

Input

第一行为N,表示有N行
后面N行表示三角形每条路的路径权1≤n,m≤100000,0≤ai≤100000,1≤xi≤n,0≤wi≤10000,1≤li≤ri≤n

Output

路径所经过的数字的总和最大的答案

Sample Input

5 
7

3 8

8 1 0

2 7 4 4

4 5 2 6 5

Sample Output

30

HINT

题解:

dp[i][j]表示从(i,j)这个位置出发后所能拿到的最大值

简单递推关系

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* */
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int dp[maxn][maxn];
int g[maxn][maxn];
int main()
{
int n=read();
for(int i=;i<=n;i++)
for(int j=;j<=i;j++)
g[i][j]=read();
for(int j=;j<=n;j++)
dp[n][j]=g[n][j];
for(int i=n-;i>=;i--)
for(int j=;j<=n;j++)
dp[i][j]=max(dp[i+][j],dp[i+][j+])+g[i][j];
printf("%d\n",dp[][]);
}

最新文章

  1. debian下Apache和tomcat整合(使用apt工具)
  2. .net(C#)访问Oracle数据库的几种免安装组件的对比
  3. SharePoint 2013 配置基于AD的Form认证
  4. e_msg_c_as_login_req 和 e_msg_c_as_login_if_no_register_req
  5. java 泛型接口示例
  6. xcode7启动页的尺寸设置
  7. 《think in python》学习-8
  8. [转]数位dp小记
  9. angular 实战系列 之 mvvm模式
  10. 使用SQL Server临时表来实现字符串合并处理
  11. iOS之 Auto Layout
  12. CentOS下 elasticsearch集群安装
  13. [翻译] 比较 Node.js,Python,Java,C# 和 Go 的 AWS Lambda 性能
  14. css样式的六种选择器
  15. ASP.NET项目答辩系统课件使用中的问题记录
  16. 【iCore4 双核心板_uC/OS-II】例程十:信号量集
  17. 【mybatis源码学习】mybtias扩展点
  18. 20155227《网络对抗》Exp2 后门原理与实践
  19. CDH 5.16.1 离线部署 &amp; 通过 CDH 部署 Hadoop 服务
  20. Java-Runoob-高级教程-实例-环境设置实例:4.Java 实例 – 如何查看当前 Java 运行的版本?

热门文章

  1. 数据库-mysql事务
  2. MongoDB-MongoDB重装系统后恢复
  3. jQuery对象与JS原生对象之间的转换
  4. hihoCoder #1185 : 连通性&#183;三(强联通分量+拓扑排序)
  5. 定制Eclipse
  6. MATLAB读写Excel文件中的数据
  7. OnClickListener接口
  8. Rookey.Frame之DAL工厂
  9. Codeforces Round #334 (Div. 1) B. Moodular Arithmetic
  10. PHP 中文字符串相关