题意:给定一个金字塔,第 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;
}

最新文章

  1. spark 官方文档(1)——提交应用程序
  2. 说说js作用域
  3. [转]TextView maxWidth maxLength maxEms 区别
  4. Texture tiling and swizzling
  5. spring mvc 第三天【注解实现springmvc Handler返回值为Object 的配置】
  6. C++浅析——虚表和虚表Hook
  7. HTML页面定时跳转方法
  8. 【nginx】配置文件的优化
  9. mysql 获取一个表中缺失的最小编号
  10. Hibernate映射之实体映射&lt;转载&gt;
  11. 图片缩放时java.lang.IllegalArgumentException: pointerIndex out of range解决方案
  12. [性能分析]linux文件描述符(转)
  13. 【javascript】数组的操作
  14. 新书发布《每天5分钟玩转Docker容器技术》
  15. openldap 编译报错MozNSS not found
  16. bzoj4596[Shoi2016]黑暗前的幻想乡 Matrix定理+容斥原理
  17. 获取X天后的日期
  18. Q查询条件
  19. java----tomcat
  20. canvas高级篇(转载)移动元素

热门文章

  1. 各个 Maven仓库 镜像(包括国内)
  2. Hide/Show running Console
  3. Linux diff patch
  4. UVA 10061 How many zero&#39;s and how many digits ? (m进制,阶乘位数,阶乘后缀0)
  5. 使用 Linux 终端 SSH 登录 VPS
  6. notepad 行替换使用指南
  7. Java中&#39;&amp;&#39;与、&#39;|&#39;或、&#39;^&#39;异或、&#39;&lt;&lt;&#39;左移位、&#39;&gt;&gt;&#39;右移位
  8. linux 下RMAN备份shell脚本
  9. gcc/交叉编译
  10. unity, surface shader access world position and localposition