题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和。

析:真是水题,学过DP的都会,就不说了。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const int maxn = 350 + 5;
int a[maxn][maxn];
int d[maxn][maxn]; int main(){
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i)
for(int j = 0; j <= i; ++j)
scanf("%d", &a[i][j]);
for(int i = n-1; i >= 0; --i){
for(int j = 0; j <= i; ++j)
d[i][j] = max(d[i+1][j], d[i+1][j+1]) + a[i][j];
}
printf("%d\n", d[0][0]);
return 0;
}

POJ 3176 Cow Bowling (水题DP)的更多相关文章

  1. POJ 3176 Cow Bowling(dp)

    POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...

  2. poj 1163 The Triangle &amp;poj 3176 Cow Bowling (dp)

    id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...

  3. POJ 3176 Cow Bowling

    Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13016   Accepted: 8598 Desc ...

  4. poj 3176 Cow Bowling(dp基础)

    Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...

  5. poj 3176 Cow Bowling(区间dp)

    题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + ...

  6. POJ - 3176 Cow Bowling 动态规划

    动态规划:多阶段决策问题,每步求解的问题是后面阶段问题求解的子问题,每步决策将依赖于以前步骤的决策结果.(可以用于组合优化问题) 优化原则:一个最优决策序列的任何子序列本身一定是相当于子序列初始和结束 ...

  7. POJ 3673 Cow Multiplication (水题)

    题意:给你两个数,求所有的数位的积的和. 析:太水了,没的说,可以先输入边算,也可以最后再算,一样.. 代码如下: #include <cstdio> #include <strin ...

  8. POJ 1488 Tex Quotes --- 水题

    POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...

  9. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

随机推荐

  1. Replication in Kafka

    Replication简介 Kafka中的Replication功能是为了给每个partition提供备份,当某个Broker挂掉时可以迅速实现故障切换(failover).我们可以在创建或修改top ...

  2. 在Eclipse中运行cmd

    第一步:设置一个新的外部配置工具 在 Eclipse 中,选择 “Run -> External Tools -> External Tools Configurations”  第二步: ...

  3. (C#基础) byte[] 之初始化, 赋值,转换。

    byte[] 之初始化赋值 用for loop 赋值当然是最基本的方法,不过在C#里面还有其他的便捷方法. 1. 创建一个长度为10的byte数组,并且其中每个byte的值为0. byte[] myB ...

  4. boost多边形交集、并集

    交集:http://www.boost.org/doc/libs/1_56_0/libs/geometry/doc/html/geometry/reference/algorithms/interse ...

  5. 【Java】SHA加密

    package sdfg; import java.math.BigInteger; import java.security.MessageDigest; import java.security. ...

  6. Hibernate-Criteria Queries

    1.实例 接口org.hibernate.Criteria针对特殊持久层类进行查询,Sesion是Criteria的工厂: Criteria crit = sess.createCriteria(Ca ...

  7. Oracle Exadata体系笔记

    Exadata一开始是以一个存储系统形式诞生的,叫做SAGE(Storage Appliance for Grid Environ ments,网格环境存储设备)   Exadata原本设计用来解决超 ...

  8. php 二维数组的排序

    写这是之前一直二维数组排名困扰.自己写的好复杂. 正题: array_mutisort 官方帮助文档 <?php// 取得列的列表foreach ($data as $key => $ro ...

  9. 你能识别这些科技公司的真假logo吗?

    快告诉我,不止我一个眼瞎~

  10. 用xsd验证xml

    using System; using System.Text; using System.Xml; namespace WebApplication1 { public partial class ...