hdu2084 数塔 DP
数字三角形,DP裸题
#include<stdio.h>
#include<string.h>
#define max(a,b) (a)>(b)?a:b int g[][],dp[][]; int max1(int i,int j){
return i>j?i:j;
} int main(){
int C;
while(scanf("%d",&C)!=EOF){
for(int q=;q<=C;q++){
int N;
scanf("%d",&N);
memset(dp,,sizeof(dp));
int i,j;
for(i=;i<=N;i++){
for(j=;j<=i;j++){
scanf("%d",&g[i][j]);
}
}
dp[][]=g[][];
for(i=;i<=N;i++){
for(j=;j<=i;j++){
if(j==)dp[i][j]=dp[i-][j]+g[i][j];
else if(j==i)dp[i][j]=dp[i-][j-]+g[i][j];
else dp[i][j]=max1(dp[i-][j-],dp[i-][j])+g[i][j];
}
}
int m=dp[N][];
for(i=;i<=N;i++)if(dp[N][i]>m)m=dp[N][i];
printf("%d\n",m);
} }
return ;
}
hdu2084 数塔 DP的更多相关文章
- HDU2084 数塔 (DP入门题)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- HDU-2084 数塔 经典dp,水
1.HDU-2084 数塔 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 3.总结:从下往上推,最后归于顶点.方程为 dp[i][j] ...
- hdu----(2084)数塔(dp)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- HDU2084:数塔(DP)
Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大 ...
- HDU 2084 数塔 (DP)
数塔 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pr ...
- 数塔~~dp学习_1
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 数塔 Time Limit: 1000/1000 MS (Java/Others) Mem ...
- USACO training course Number Triangles 数塔 /// DP oj10122
题目大意: ...就是数塔 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 7+3+8+7+5=30 ...
- [hdu1176]免费馅饼(数塔dp)
题意:中文题,不解释了 = = 解题关键:逆推,转化为数塔dp就可以了 dp[i][j]表示在i秒j位置的最大值. 转移方程:$dp[i][j] = \max (dp[i + 1][j],dp[i + ...
- HDU 1176 免费馅饼(数塔dp)
一开始被吓到了,后来再仔细一读发现就是一个数塔,没有那么复杂 #include<stdio.h> #include<string.h> #include<algorith ...
随机推荐
- json-rpc和restful
json-rpc是一种动作 restful 是一种资源 RPC 所谓的远程过程调用 (面向方法) SOA 所谓的面向服务的架构(面向消息) REST 所谓的 Representational stat ...
- win10 自己DIY的arp绑定小脚本
@echo off&mode con cols=80 lines=22&title ARP_bind Tools setlocal enabledelayedexpansion rem ...
- English trip -- VC(情景课)5 B Places around town 城市设施
Vocabulary focus 核心词汇 drugstore 药店: pill n. 药丸:弹丸,子弹:口服避孕药 medicine n. 药:医学:内科:巫术 hos ...
- ViewPagerIndicator+viewpager的简单使用,不需要导入Library包
ViewPagerIndicator作为一款分页指标小部件兼容ViewPager,封装上做得非常不错,目前已为众多知名应用所使用. ViewPagerIndicator+viewpager实现如下效果 ...
- Gluttony CodeForces - 892D (构造,思维)
题面: You are given an array a with n distinct integers. Construct an array b by permuting a such that ...
- hdu2609 最小表示法
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- 2-24-源码编译搭建LAMP环境-作业 ( By 小甘丶 )
安装上课的内容要求: 实验环境: VMware Virtual Machine : System Version: CentOS6.8 ( Gan35 ) IP Address : 192.168.3 ...
- C# Winform程序以及窗体运行的唯一性汇总
经常看到有人讨论程序运行唯一性或者窗体运行的唯一性问题.我之前也写了一些文章,在此把它进行整理汇总. 如果是程序的唯一性问题,我之前的一篇文章已经写得很全面,可以参看. C# Winform如何使自己 ...
- vs2012修改代码编辑区域的背景色
- Java容器——Map接口
1.定义 Map用于保存存在映射关系<key, value>的数据.其中key值不能重复(使用equals()方法比较),value值可以重复. 2.常用实现类 HashMap:和Hash ...