POJ 3176 简单DP
Cow Bowling
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 16448 Accepted: 10957
Description
The cows don’t use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this:
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
Line 1: A single integer, N
Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.
Output
Line 1: The largest sum achievable using the traversal rules
Sample Input
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Sample Output
30
Hint
Explanation of the sample:
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.
题意:一个n层的三角形,从第一行第一列开始向下走,每次只能向下一行且只能走到与之到相邻的两块,求到最后一行路程的最大值。
解题思路:动规
f[i][j]表示到第i行第j列路程的最大值
走到第i行第j列的路程只能与走到第i-1行第j列和第i-1行第i-1列有关
不难写出状态转移方程为:f[i][j]=max(f[i][j]+f[i-1][j-1],f[i][j]+f[i-1][j]);
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,f[666][666];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
scanf("%d",&f[i][j]);
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
f[i][j]=max(f[i][j]+f[i-1][j-1],f[i][j]+f[i-1][j]);
}
}
for(int i=1;i<=n;i++)
{
if(f[n][i]>f[0][0]) f[0][0]=f[n][i];
}
printf("%d",f[0][0]);
}
POJ 3176 简单DP的更多相关文章
- poj 1579 简单dp由下往上
#include<stdio.h> #include<string.h> #define N 22 int dp[N][N][N]; int main() { int n,m, ...
- POJ 3176 Cow Bowling(dp)
POJ 3176 Cow Bowling 题目简化即为从一个三角形数列的顶端沿对角线走到底端,所取得的和最大值 7 * 3 8 * 8 1 0 * 2 7 4 4 * 4 5 2 6 5 该走法即为最 ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
- poj 1163 The Triangle &poj 3176 Cow Bowling (dp)
id=1163">链接:poj 1163 题意:输入一个n层的三角形.第i层有i个数,求从第1层到第n层的全部路线中.权值之和最大的路线. 规定:第i层的某个数仅仅能连线走到第i+1层 ...
- 【POJ - 2533】Longest Ordered Subsequence (最长上升子序列 简单dp)
Longest Ordered Subsequence 搬中文 Descriptions: 给出一个序列,求出这个序列的最长上升子序列. 序列A的上升子序列B定义如下: B为A的子序列 B为严格递增序 ...
- poj1189 简单dp
http://poj.org/problem?id=1189 Description 有一个三角形木板,竖直立放.上面钉着n(n+1)/2颗钉子,还有(n+1)个格子(当n=5时如图1).每颗钉子和周 ...
- poj1163The Triangle(简单DP)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...
- POJ1088:滑雪(简单dp)
题目链接: http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一 ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- 激活、复制、使用R/3标准数据源(RSA5、RSA6、RSA1)
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- WIN10图标显示异常
1.打开控制面板,右上边查看方式选择边小图标显示 2.打开显示里面的自定义缩放级别 3.设置级别为125% 然后点击 应用 4.注销或者重启,然后将异常的快捷方式点击打开,就会恢复正常,至少我的是回 ...
- Flex http请求
下面类支持POST和GET请求,请求数据和出错将返回 package com.sole.util { import flash.events.Event; import flash.events.HT ...
- iOS - iOS 适配
前言 什么是适配: 适应.兼容各种不同的情况. iOS 开发中,适配的常见种类: 1)系统适配, 针对不同版本的操作系统进行适配. 2)屏幕适配,针对不同大小的屏幕尺寸进行适配. iPhone 的尺寸 ...
- js之oop <四>对象管理
对象扩展管理 Object.isExtensible() 检测对象是否可扩展(一般返回true).Object.preventExtensions() 防止对象扩展. var p = {p1:&quo ...
- zoj3494BCD Code(ac自动机+数位dp)
l链接 这题想了好一会呢..刚开始想错了,以为用自动机预处理出k长度可以包含的合法的数的个数,然后再数位dp一下就行了,写到一半发现不对,还要处理当前走的时候是不是为合法的,这一点无法移到trie树上 ...
- openfire源码修改聊天消息发送内容
/** * $RCSfile: MessageRouter.java,v $ * $Revision: 3007 $ * $Date: 2005-10-31 13:29:25 -0300 (Mon, ...
- Deep Learning 1_深度学习UFLDL教程:Sparse Autoencoder练习(斯坦福大学深度学习教程)
1前言 本人写技术博客的目的,其实是感觉好多东西,很长一段时间不动就会忘记了,为了加深学习记忆以及方便以后可能忘记后能很快回忆起自己曾经学过的东西. 首先,在网上找了一些资料,看见介绍说UFLDL很不 ...
- Android 如何解决数据库多线程锁的问题
防止多个线程又是读取又是写入 网上找到的方法: 对于这样的问题,解决的办法就是keep single sqlite connection,保持单个SqliteOpenHelper实例,同时对所有数据库 ...
- [kylin] 部署kylin服务
一.工具准备 zookeeper3.4.6 (hadoop.hbase 管理工具) Hadoop. Hbase1.1.4 Kylin1.5.0-HBase1.1.3 Jdk1.7.80 Hive 二. ...