杭电三部曲一、基本算法;19题 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.
Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.
思路:看到题目一开始想用搜索做但是数据范围太大;如果用广搜的话,只是最后一步就需要2*10^105个空间肯定会超时,效率也不高;所以,改用dp;记录到第i行第j列是和的最大值;
#include<iostream>
#include<cstdio> using namespace std; int max(int &a,int &b)
{
return a>b?a:b;
} int main()
{
int n;
cin>>n;
int i,j;
int dp[]={};//dp数组,
int s[]={};//存储数组;
for(i=;i<=n;i++)
{
for(j=;j<=i;j++)//录入第i行
cin>>s[j];
for(j=i;j>;j--)//对dp数组进行跟新;
dp[j]=max(dp[j],dp[j-])+s[j];
}
j=;
for(i=;i<=n;i++)
if(dp[i]>j)j=dp[i];//查找最大值;
cout<<j<<endl;//输出最大值;
return ;
}
杭电三部曲一、基本算法;19题 Cow Bowling的更多相关文章
- 2022“杭电杯”中国大学生算法设计超级联赛(6)- 1011 Find different
2022"杭电杯"中国大学生算法设计超级联赛(6)- 1011 Find different 比赛时队友开摆,还剩半个小时,怎么办?? 当然是一起摆 Solution 看到这个题没 ...
- 一个人的旅行 HDU杭电2066【dijkstra算法 || SPFA】
pid=2066">http://acm.hdu.edu.cn/showproblem.php? pid=2066 Problem Description 尽管草儿是个路痴(就是在杭电 ...
- HDU 4901(杭电多校训练#3 1005题)The Romantic Hero(DP)
题目地址:HDU 4901 这题没想到最后竟然可以做出来.. .. 这题用了两次DP,先从前往后求一次异或的.再从后往前求一次与运算的. 各自是 1:求异或的时候,定义二维数组huo[1000][10 ...
- 杭电 1155 Bungee Jumping(物理题)
Problem Description Once again, James Bond is fleeing from some evil people who want to see him dead ...
- HDU 4920(杭电多校训练#5 1010 题) Matrix multiplication(不知道该挂个什么帽子。。。)
题目地址:pid=4920">HDU 4920 对这个题简直无语到极点. . .竟然O(n^3)的复杂度能过....方法有三.. 1:进行输入优化和输出优化. . (前提是你的输入优化 ...
- 畅通project续HDU杭电1874【dijkstra算法 || SPFA】
http://acm.hdu.edu.cn/showproblem.php?pid=1874 Problem Description 某省自从实行了非常多年的畅通project计划后.最终修建了非常多 ...
- 畅通project再续 HDU杭电1875 【Kruscal算法 || Prim】
Problem Description 相信大家都听说一个"百岛湖"的地方吧.百岛湖的居民生活在不同的小岛中.当他们想去其它的小岛时都要通过划小船来实现.如今政府决定大力发展百岛湖 ...
- Choose the best route HDU杭电2680【dijkstra算法 || SPFA】
http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one ...
- Rikka with Travels(2019年杭电多校第九场07题+HDU6686+树形dp)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 定义\(L(a,b)\)为结点\(a\)到结点\(b\)的路径上的结点数,问有种\(pair(L(a,b),L(c,d))\)取值,其中结点\ ...
随机推荐
- hdu1032
#include <iostream> using namespace std; int main() { int a,b,t,i,max; while(cin >> a &g ...
- iOS10 CAAnimationDelegate的适配
最近在xcode8打开之前的动画代码,看到如下警告
- Git之”make sure you have the correct access…”
git 命令在windows下无法使用pull.fetch.push等命令,提示 “please make sure you have the correct access and the repos ...
- dplyr 数据操作 常用函数(4)
接下来我们继续了解一些dplyr中的常用函数. 1.ranking 以下各个函数可以实现对数据进行不同的排序 row_number(x) ntile(x, n) min_rank(x) dense_r ...
- netty初探(2)
上一篇 netty(1) 一.TCP/IP 流式传输 在上文演示了2进制流式传输引起的TCP拆包问题,这里继续演示文本型的传输问题,文本型的可以有以下几种策略 1.1 以特殊字符表示结尾 HTTP协议 ...
- concurrent实用类
improt java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.RejectedExecutionHandler; ...
- 【实验室笔记】C#以本地时间创建txt文件
前段时间做的一个小项目,要求上位机在打开时候,以打开软件的系统时间的建立一个txt文件来存储下位机发送来的数据. 在第一版上位机上,取名的办法太弱了,先是读取系统时间,然后截取字符串,太笨拙.昨天,查 ...
- java-jvisualvm远程监控tomcat
一.修改要访问的远程主机(Linux)相关文件,本文档只介绍了java-jvisualvm的JMX方式: 1.打开$CATALINA_HOME/bin/startup.sh, 找到倒数第二行(也就是e ...
- ueditor1.4.3 在IE8下的 BUG
ueditor1.4.3 .net 版 在IE8 下,多图片上传完成后,点击确认时报错,无法插入图片到编辑器中 原因是 ueditor.all.js 中的 24835 行 if (whitList[ ...
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...