数塔

点我挑战题目

题意分析

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)的更多相关文章

  1. HDU 2084 数塔 (DP)

    数塔 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pr ...

  2. hdoj 2084 数塔

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  3. HDOJ --- 2084数塔

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  4. Hdoj 2084.数塔 题解

    Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大 ...

  5. hdu 2084 数塔 (简单dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory L ...

  6. 数塔~~dp学习_1

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others)    Mem ...

  7. HDU 2084 数塔(简单DP入门)

    数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  8. 题解报告:hdu 2084 数塔(递推dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这 ...

  9. HDU 2084 数塔 (dp)

    题目链接 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数 ...

随机推荐

  1. 会声会影X10x9x8最新教程

    会声会影X10x9x8最新最全教程,全部都是干货,包含素材的,下载地址:百度网盘, https://pan.baidu.com/s/1AyVS-C_VcTEz_ir70u08xQ 以下为部分内容截图: ...

  2. XSS--PHPwind5.3复现

    xss再分析 短payload <svg/onload=alert(1)> <body/onfocus=alert``> <body/onfocus=confirm``& ...

  3. 使用gitlab时候 fork仓库不会实时从主仓库更新解决方案

    付费用户可以使用现成的方案,地址见 链接 但是私有gitlab时候,需要手动进行如下操作 1. Clone your fork: git clone git@github.com:YOUR-USERN ...

  4. 通过 Python_Faker 生成测试数据

    通过 Python_Faker 生成测试数据 一.介绍 在软件需求.开发.测试过程中,有时候需要使用一些测试数据,针对这种情况,我们一般要么使用已有的系统数据,你不可能通过手工来生成(最傻的方法)可能 ...

  5. Spring ApplicationContext 简介

    ApplicationContext是对BeanFactory的扩展,实现BeanFactory的所有功能,并添加了事件传播,国际化,资源文件处理等.   configure locations:(C ...

  6. [CH0304]IncDec Sequence

    和NOIP2018DAY1T1类似的题目,但思维难度高多了. 这题既可以抬高路面,也可以降低路面,而且目标平面不确定,就难起来了. 但是两道题的基本思路几乎一样,同样我们将 2~n 的高度差分,1之所 ...

  7. 1208: [HNOI2004]宠物收养所

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 12030 Solved: 4916 Description ...

  8. jupyter notebook 使用cmd命令窗口打开

    第一步:将文件路径改为你需要使用文件所在的路径 第二部:   jupyter notebook

  9. Reject Inference: Your Data is Deceiving You

    Keyword: Reject Inference Suppose there is a dataset of several attributes, including working condit ...

  10. Dictionary tabPage使用

    public override bool AccptChange() { //if (oldvalue == null || oldvalue.Count <= 0) //{ // return ...