POJ 3176 Cow Bowling (水题DP)
2024-10-18 22:32:03
题意:给定一个金字塔,第 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;
}
最新文章
- spark 官方文档(1)——提交应用程序
- 说说js作用域
- [转]TextView maxWidth maxLength maxEms 区别
- Texture tiling and swizzling
- spring mvc 第三天【注解实现springmvc Handler返回值为Object 的配置】
- C++浅析——虚表和虚表Hook
- HTML页面定时跳转方法
- 【nginx】配置文件的优化
- mysql 获取一个表中缺失的最小编号
- Hibernate映射之实体映射<;转载>;
- 图片缩放时java.lang.IllegalArgumentException: pointerIndex out of range解决方案
- [性能分析]linux文件描述符(转)
- 【javascript】数组的操作
- 新书发布《每天5分钟玩转Docker容器技术》
- openldap 编译报错MozNSS not found
- bzoj4596[Shoi2016]黑暗前的幻想乡 Matrix定理+容斥原理
- 获取X天后的日期
- Q查询条件
- java----tomcat
- canvas高级篇(转载)移动元素
热门文章
- 各个 Maven仓库 镜像(包括国内)
- Hide/Show running Console
- Linux diff patch
- UVA 10061 How many zero&#39;s and how many digits ? (m进制,阶乘位数,阶乘后缀0)
- 使用 Linux 终端 SSH 登录 VPS
- notepad 行替换使用指南
- Java中&#39;&;&#39;与、&#39;|&#39;或、&#39;^&#39;异或、&#39;<;<;&#39;左移位、&#39;>;>;&#39;右移位
- linux 下RMAN备份shell脚本
- gcc/交叉编译
- unity, surface shader access world position and localposition