The Triangle 经典DP
题意:数塔问题
思路:1:递归。2:递推。3:记忆化搜索。《刘汝佳,第九章》
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int data[105][105];
int main ()
{
int n;
while(~scanf("%d",&n)){
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++)
scanf("%d",&data[i][j]);
for(int i=n-1;i>=1;i--)
for(int j=1;j<=i;j++)
data[i][j]+=max(data[i+1][j],data[i+1][j+1]);
printf("%d\n",data[1][1]);
}
return 0;
}
The Triangle 经典DP的更多相关文章
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- poj1458 求最长公共子序列 经典DP
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45763 Accepted: 18 ...
- NYOJ - 矩形嵌套(经典dp)
矩形嵌套时间限制:3000 ms | 内存限制:65535 KB 描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a<c,b< ...
- 51nod 1412 AVL树的种类(经典dp)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1412 题意: 思路: 经典dp!!!可惜我想不到!! $dp[i][k] ...
- NYOJ 16 矩形嵌套(经典DP)
http://acm.nyist.net/JudgeOnline/problem.php?pid=16 矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度: ...
- 120. Triangle(Array; DP)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- poj 1050 To the Max 最大子矩阵和 经典dp
To the Max Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- CS Academy Distinct Neighbours(经典dp)
CS Academy Distinct Neighbours(经典dp) 题意: 求相邻无相同数字的合法的排列数 题解: 题解 先将相同的数字分为一类,假设共有n组 定义\(dp[i][j]\)表示前 ...
- 【经典dp 技巧】8.13序列
经典的拆绝对值 题目大意 给定$n$个具有顺序的序列,允许对每个序列循环移动.记第$i$个序列尾元素为$x$,$i+1$个序列首元素为$y$,定义其连接收益为$|x-y|*i$,求$n$个序列连接最大 ...
随机推荐
- javascript模板引擎template.render使用
<script type="text/javascript"> function test(){ //你的方法 } </script> 如上代码:通常我们见 ...
- Chapter 2 Open Book——8
But as far as I could tell, life worked that way most of the time. 但是即使我这么说,生活大多数时间还是这样的. 但就我所能告诉你的, ...
- Balancing Symbols
symbols匹配问题 #include<iostream> #include<string> using namespace std; struct Node { char ...
- openwrt默认不开启wifi
Openwrt默认不开启wifi,要开启的话, 修改这个文件: openwrt/trunk/package/kernel/mac80211/files/lib/wifi/mac80211.sh. 滚到 ...
- 使用CodeFirst实现动态建库
一.业务分析 以我们平时注册今目标为例,我们在注册今目标的过程中,具体步骤是这样的: 图1 今目标登陆流程 详细解释一下: 第一步:注册界面.输入手机号或者邮箱,点击确定进入基本信息界面. 第二步:基 ...
- MySQL半同步复制的数据一致性探讨微信后台团队实践【转】
MySQL是一个RDBMS(关系型数据库管理系统),由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.由于其体积小.速度快.拥有成本低,尤其是开放源码这一特点,广受各大企业欢迎,包括 ...
- listview解决滑动条目的时候背景变为黑色的问题
方式一:java代码: listView.setCacheColorHint(0); 方式二:布局文件 <ListView android:id="@+id/listView1&quo ...
- 二维 ST POJ 2019
题目大意:给你一个n*n的矩阵,每次给你一个点(x,y),以其为左上角,宽度为b的矩阵中最小的数值和最大数值的差是多少? 一共k个询问. 思路:简单的二维st. 定义dp(i,j,k,L)表示以(i ...
- git conflict
https://wiki.52north.org/bin/view/Documentation/ResolveMergeConflictsInGitEclipse Note that you can ...
- STM32F407的硬件I2C
源:STM32F407的硬件I2C 我使用的是STM32的固件库. 硬件模块使用之前必须配置其参数,I2C的配置如下: void IIC_Config(void) { GPIO_InitTypeDef ...