POJ3176--Cow Bowling(动态规划)
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
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int data[][];
int dp[];
int main(){
int n;
cin>>n;
for(int i=;i<=n;i++)
for(int j=;j<=i;j++)
cin>>data[i][j];
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
for(int j=i;j>=;j--){//这里为何j要逆序开始算呢?等号右边的dp数组是对应的i-1,如果升学计算的话,等号左边被赋值之后,也就意味着i-1数组被修改了,而下次计算正好需要这次修改的原来的数组的值
dp[j]=max(dp[j-],dp[j])+data[i][j];
}
}
int m=dp[];
for(int i=;i<=n;i++){
if(dp[i]>m)
m=dp[i];
}
cout<<m;
return ;
}
#include<iostream>
#include<string.h>
using namespace std;
int way[MAXN],dp[MAXN];
int N;
void Input()
{
cin>>N;
memset(dp,,sizeof(dp));
for (int i=; i<=N; i++)
{
for (int j=; j<=i; j++)
scanf("%d",&way[j]);
for (int j=i; j>=; j--)
dp[j]=max(dp[j],dp[j-])+way[j];
}
}
void Output()
{
int ret=dp[];
for (int i=; i<=N; i++)
if (ret<dp[i]) ret=dp[i];
cout<<ret<<endl;
}
int main()
{
Input();
Output();
return ;
}
POJ3176--Cow Bowling(动态规划)的更多相关文章
- POJ3176——Cow Bowling(动态规划)
Cow Bowling DescriptionThe cows don't use actual bowling balls when they go bowling. They each take ...
- POJ3176 Cow Bowling 2017-06-29 14:33 23人阅读 评论(0) 收藏
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19173 Accepted: 12734 Des ...
- Poj3176 Cow Bowling (动态规划 数字三角形)
Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...
- POJ - 3176 Cow Bowling 动态规划
动态规划:多阶段决策问题,每步求解的问题是后面阶段问题求解的子问题,每步决策将依赖于以前步骤的决策结果.(可以用于组合优化问题) 优化原则:一个最优决策序列的任何子序列本身一定是相当于子序列初始和结束 ...
- poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)
经典的数塔模型. 动态转移方程: dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+p[i][j]; #include <iostream> #include ...
- POJ3176:Cow Bowling(数字三角形问题)
地址:http://poj.org/problem?id=3176 题目解析:没什么好说的,之前上课时老师讲过.从下往上找,每一个三角形的顶点可由两个角加上顶点的值 两种方式得到 ,用dp数组保存下最 ...
- 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 3176 Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13016 Accepted: 8598 Desc ...
- Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15585 Accepted: 10363 Descrip ...
- POJ 3176:Cow Bowling
Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13464 Accepted: 8897 Desc ...
随机推荐
- .net中几个经常用到的字符串的截取
string str="123abc456";int i=3;1 取字符串的前i个字符 str=str.Substring(0,i); // or str=str.Remov ...
- 5F - Coin Change
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make c ...
- python之初接触
编程语言相关 1什么是编程语言 编程语言即语言,语言的本质就是沟通,因而编程语言与英语 .法语.日语等所有语言并无区别,只不过英语是人与人之间沟通的介质,而编程语言则是程序员与计算机沟通的介质. 程序 ...
- Codeforces559C Gerald and Giant Chess
一道计数类\(DP\) 原题链接 我们可以先计算从左上角到右下角总的路径,再减去经过黑色方格的路径即是答案. 总路径数可以用组合数直接计算:\(C_{H+W-2}^{H-1}\) 因为从左上角到右下角 ...
- NOIP需要掌握的内容(大致
1.排序算法(快排.选择.冒泡.堆排序.二叉排序树.桶排序)2.DFS/BFS 剪枝 哈希表3.树 ①遍历 ②二叉树 ③二叉排序树(查找.生成.删除) ④堆(二叉堆.左偏树.堆排序) ...
- UI设计师需要熟记的45个快捷键Windows、Mac
大家都知道PS快捷键很多,其实没必要都记住,今天为大家整理了45个比较实用的,别忘了收藏. 图层 填充图层 MAC: Alt+Backspace (前景) or Cmd+Backspace (背景) ...
- idea窗口下方滚动条不明显设置
在使用idea时,下方的滚动条老是显示不明显,每次点击拖拽都很费劲,在网上找了很多相关设置,最后确定了一个最好的办法解决问题: Shift (上档) + 鼠标滚动,这样就可以横向翻滚了,很方便 此方 ...
- Koko Eating Bananas LT875
Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The g ...
- 用visual studio 2017来调试python
https://www.visualstudio.com/zh-hans/thank-you-downloading-visual-studio/?sku=Professional&rel=1 ...
- python正则表达式获取两段标记内的字符串
比如获取绿色字符串 ModelData.PayTableData =[{"}, {"}, {"}]; ModelData.PayTableData1 =[{"} ...