HDOJ.2084 数塔(DP)
数塔
题意分析
DP的思想,自上而下计算。
[这几天比较忙 有空补上]
代码总览
/*
Title:HDOJ.2084
Author:pengwill
Date:2017-1-14
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ma 101
using namespace std;
int map[ma][ma];
int dp[ma][ma];
void get(int n)
{
int i,j;
for(i = 0;i<n;i++){
for(j = 0; j<=i;j++){
if(!i&&!j){
dp[i][j] = map[i][j];
}else if(!j){
dp[i][j] = dp[i-1][j] + map[i][j];
}else if(j == i){
dp[i][j] = dp[i-1][j-1] + map[i][j];
}else{
dp[i][j] = max(dp[i-1][j] + map[i][j],dp[i-1][j-1] + map[i][j]);
}
}
}
}
int main()
{
int n,t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int i,j;
for(i = 0;i<n;i++){
for(j = 0; j<=i;j++){
scanf("%d",&map[i][j]);
}
}
get(n);
int max = 0;
for(i = 0;i<n;i++){
if(max<dp[n-1][i]){
max = dp[n-1][i];
}
}
printf("%d\n",max);
}
return 0;
}
HDOJ.2084 数塔(DP)的更多相关文章
- HDU 2084 数塔 (DP)
数塔 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pr ...
- hdoj 2084 数塔
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- HDOJ --- 2084数塔
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- Hdoj 2084.数塔 题解
Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大 ...
- hdu 2084 数塔 (简单dp)
http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others) Memory L ...
- 数塔~~dp学习_1
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- HDU 2084 数塔(简单DP入门)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- 题解报告:hdu 2084 数塔(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这 ...
- HDU 2084 数塔 (dp)
题目链接 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数 ...
随机推荐
- 「Python」conda与pip升级所有的包
conda: conda update --a pip: pip freeze --local | grep -v '^-e' | cut -d = -f 1 | xargs -n1 sudo pip ...
- Objective-C description方法 SEL类型
description方法 #import "Person.h" @implementation Person - (void) setAge : (int) age { _age ...
- leetcode-三数之和(java)
三数之和 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可 ...
- C++ ifndef /define/ endif 作用和用法
ifndef/define/endif”主要目的是防止头文件的重复包含和编译 比如你有两个C文件,这两个C文件都include了同一个头文件.而编译时,这两个C文件要一同编译成一个可运行文件,于是问题 ...
- Ubuntu—安装并运行sublime
step1 到官网看看 https://www.sublimetext.com/3 step2 根据版本选择,我的是32位的 step3 ubuntu终端安装 (1)切换目录 -$ cd /opt ...
- Android 平台 HTTP网速测试 案例 API 分析
作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/25996817 工信部规定的网速测试标准 : 除普通网页测速 ...
- Python中对变量是否为None的判断
三种主要的写法有: 第一种:if X is None; 第二种:if not X: 当X为None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()这 ...
- 第一届"进化论杯"月赛 解题报告
Problem A: derivative 思路:水题.算出二阶导数,直接 printf 结果. 在求出二阶导数后可以不立刻化简,此时式中带有大量 e^(-x) 项.此时直接可以代入 ln|x0|,把 ...
- 如何用vs查看框架函数管道模型
调试状态下 函数调用的 代码图,我们可以看到MVC框架的函数管道模型 源文章标题: 源文章:https://www.cnblogs.com/1996V/p/9037603.html 扩展阅读:http ...
- return语句的用法
1.return语句的作用:a.返回一个值,这个值可以是任意类型.b.使程序返回到操作系统(即终止程序)2.java中对于一个函数,不论有没有返回值类型,都可以带有return 语句.但是区别在于,r ...