【POJ 3176】Cow Bowling(DP)
Description
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
Then the other cows traverse the triangle starting from its tip and moving "down" to one of the two diagonally adjacent cows until the "bottom" row is reached. The cow's score is the sum of the numbers of the cows visited along the way. The cow with the highest score wins that frame.
Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.
Input
Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.
Output
Sample Input
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output
30
Hint
7
*
3 8
*
8 1 0
*
2 7 4 4
*
4 5 2 6 5
The highest score is achievable by traversing the cows as shown above.
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,a[][],ans[][],maxans;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
for(int j=;j<=i;j++)
scanf("%d",&a[i][j]);
for(int i=;i<=n;i++){
for(int j=;j<=i;j++){
ans[i][j]=max(ans[i-][j],ans[i-][j-])+a[i][j];
maxans=max(ans[i][j],maxans);
}
}
printf("%d",maxans);
return ;
}
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,i,j,a[][];
int main(){
scanf("%d",&n);
for(i=;i<=n;i++)
for(j=;j<=i;j++)
scanf("%d",&a[i][j]);
for(i=n-;i>=;i--)
for(j=;j<=i;j++)
a[i][j]+=max(a[i+][j],a[i+][j+]);
printf("%d",a[][]);
return ;
}
【POJ 3176】Cow Bowling(DP)的更多相关文章
- 【POJ 3176】Cow Bowling
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- 【POJ - 3045】Cow Acrobats (贪心)
Cow Acrobats Descriptions 农夫的N只牛(1<=n<=50,000)决定练习特技表演. 特技表演如下:站在对方的头顶上,形成一个垂直的高度. 每头牛都有重量(1 & ...
- 【poj 3167】Cow Patterns(字符串--KMP匹配+数据结构--树状数组)
题意:给2个数字序列 a 和 b ,问按从小到达排序后,a中的哪些子串与b的名次匹配. a 的长度 N≤100,000,b的长度 M≤25,000,数字的大小 K≤25. 解法:[思考]1.X 暴力. ...
- BZOJ 2296【POJ Challenge】随机种子(构造)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2296 [题目大意] 给出一个数x,求一个10的16次以内的数使得其被x整除并且数字包含 ...
- 【bzoj 1190】梦幻岛宝珠(DP)
这题是在01背包问题的基础上,扩充了重量,需要用时间换空间. 思路: 1.仔细看题,注意到重量wi为a*2^b(a<=10,b<=30),很容易想到要按 b 分开做背包的DP.接下来的重点 ...
- 【POJ 1273】Drainage Ditches(网络流)
一直不明白为什么我的耗时几百毫秒,明明差不多的程序啊,我改来改去还是几百毫秒....一个小时后:明白了,原来把最大值0x3f(77)取0x3f3f3f3f就把时间缩短为16ms了.可是为什么原来那样没 ...
- 【POJ - 3984】迷宫问题(dfs)
-->迷宫问题 Descriptions: 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 ...
- 【POJ - 3176】牛保龄球 (简单dp)
牛保龄球 直接中文了 Descriptions 奶牛打保龄球时不使用实际的保龄球.它们各自取一个数字(在0..99范围内),然后排成一个标准的保龄球状三角形,如下所示: 7 3 8 8 1 0 2 7 ...
- 【POJ 3167】Cow Patterns (KMP+树状数组)
Cow Patterns Description A particular subgroup of K (1 <= K <= 25,000) of Farmer John's cows l ...
随机推荐
- 关于 CSLA 服务器部署WCF访问出错的问题
MDAA项目 在以前的项目中,只要部署,从来没有发生过 通过WCF访问出错的问题,但是此次却出现如下问题: 2018-04-21 13:45:39,744 [119] ERROR Galaxy.OTC ...
- angularjs springMVC 交互
AngularJS中的$resource使用与Restful资源交互 1.AngularJS中的 $resource 这个服务可以创建一个资源对象,我们可以用它非常方便地同支持RESTful的服务端数 ...
- 如何实现.net程序的进程注入
原文:如何实现.net程序的进程注入 如何实现.net程序的进程注入 周银辉 进程注入比较常见,比如用IDE调试程序以及一些Sp ...
- tomcate+keepalived配置双机热备
环境清单: 应用1:192.168.51.101 应用2:192.168.51.75 虚拟IP:192.168.51.179 一.安装Tomcat(参照其他文档): 二.部署应用,并修改响应的端口(9 ...
- 20135218 Linux 实践二 编译模块
20135218 姬梦馨 1.编写模块代码 模块构造函数:执行insmod或modprobe指令加载内核模块时会调用的初始化函数.函数原型必须是module_init(),括号内是函数指针 模块析构函 ...
- 语音笔记:CTC
CTC全称,Connectionist temporal classification,可以理解为基于神经网络的时序类分类.语音识别中声学模型的训练属于监督学习,需要知道每一帧对应的label才能进行 ...
- CSS字体大小之em,px,百分比
首先要记住网页中常规字体的大小为16px. px是用来设置字体的绝对大小.通常为用于物理值的设置.我们在互联网上看到的常规字体大小为16px.而em是指相对于父元素的大小.1em是父元素的1倍,2em ...
- myBatis插件(plugins)
MyBatis 允许你在已映射语句执行过程中的某一点进行拦截调用.默认情况下,MyBatis 允许使用插件来拦截的方法调用包括: Executor (update, query, flushState ...
- RBAC权限管理及使用原生PHP实现
关于RBAC的原理讲解在网上可以找到很多,推荐:编程浪子的RBAC讲解,本篇博客就不再累述RBAC的原理到底是什么样的. 传统的权限控制有ACL和RBAC方式,ACL的耦合度很高,扩展性不佳,RBAC ...
- shell脚本--函数
shell的函数和Javacript和php的函数声明一样,只不过shell在调用函数的时候,只需要写函数名就可以调用函数,注意不要在函数名后面加括号 创建并使用函数 #!/bin/bash #文件名 ...