HDU 1087 Super Jumping! Jumping! Jumping!【DP】
解题思路:题目的大意是给出一列数,求这列数里面最长递增数列的和
dp[i]表示到达地点i的最大值,那么是如何达到i的呢,则我们可以考虑没有限制条件时候的跳跃,即可以从第1,2,3,---,i-1个地点跳跃到i,
而题目限定了,跳到的那个点的数要比开始跳的那个点的数大
所以,状态转移方程式为
for(i=1;i<=n;i++)
for(j=0;j<i;j++)
if(a[j]>a[i])
dp[i]=max(dp[j]+a[i],dp[i]);//找出到达地点i的最大值
反思:本来想的是如果给了n个点的话,那么我再加一个点,则n+1点变成终点,则不管怎么跳,都会到达终点,所以dp[n+1]即为所求
不过没有写出来,最后还是每次求出一个dp的值来比较求到了最大值。
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23935 Accepted Submission(s): 10519
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path. Your task is to output the maximum value according to the given chessmen list.#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[1005],a[1005];
int main()
{
int n,i,j,maxx;
while(scanf("%d",&n)!=EOF&&n)
{
memset(dp,0,sizeof(dp));
maxx=dp[0];
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
for(j=0;j<i;j++)
{
dp[i]=max((dp[j]+a[i])*(a[i]>a[j]),dp[i]);
if(dp[i]>maxx)
maxx=dp[i];
}
}
printf("%d\n",maxx);
}
}
HDU 1087 Super Jumping! Jumping! Jumping!【DP】的更多相关文章
- HDU 1024 Max Sum Plus Plus【DP】
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we ...
- HDU 1087 Super Jumping! Jumping! Jumping
HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...
- HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】
HDOJ_1087_Super Jumping! Jumping! Jumping! [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- 【dp】动归总结
原标题:[DP专辑]ACM动态规划总结 转载自 http://blog.csdn.net/cc_again?viewmode=list http://blog.csdn.net/cc_again/ar ...
- Kattis - honey【DP】
Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...
- HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】
HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...
- HDOJ 1501 Zipper 【DP】【DFS+剪枝】
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ 1257 最少拦截系统 【DP】
HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDOJ 1159 Common Subsequence【DP】
HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- POJ_2533 Longest Ordered Subsequence【DP】【最长上升子序列】
POJ_2533 Longest Ordered Subsequence[DP][最长递增子序列] Longest Ordered Subsequence Time Limit: 2000MS Mem ...
随机推荐
- MarkDown 语法备份
标题 标题1 标题2 标题3 标题4 标题5 无序列表 飞雪连天射白鹿 书神侠倚碧鸳 有序列表 飞雪连天射白鹿 笑书神侠倚碧鸳 超链接 百度 图片 粗体和斜体 粗体 斜体 表格 左对齐标题 右对齐标题 ...
- Java基础——选择排序、冒泡排序
1.选择排序 原理是直接从待排序数组里选择一个最小(或最大)的数字,每次都拿一个最小数字出来, 顺序放入新数组,直到全部拿完 代码演示: public class Test3 { public sta ...
- layui的多文件列表上传功能前端代码
html页面的代码(注意:引入layui相关的css): <div class="layui-upload" style="margin-left: 130px&q ...
- DataTables入门
转载 https://blog.csdn.net/gfd54gd5f46/article/details/65938189
- CentOS 6.5下部署日志服务器 Rsyslog+LogAnalyzer+MySQL
简介 LogAnalyzer 是一款syslog日志和其他网络事件数据的Web前端.它提供了对日志的简单浏览.搜索.基本分析和一些图表报告的功能.数据可以从数据库或一般的syslog文本文件中获取,所 ...
- TensorFlow+实战Google深度学习框架学习笔记(7)-----队列与多线程
一.创建一个队列: FIFOQueue:先进先出 RandomShuffleQueue:会将队列中的元素打乱,每次出列操作得到的是从当前队列所有元素中随机选择的一个. 二.操作一个队列的函数: enq ...
- 利用after和before伪类实现chrome浏览器tab选项卡斜边纯css无图制作笔记
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- BZOJ 3307 雨天的尾巴 (树上差分+线段树合并)
题目大意:给你一棵树,树上一共n个节点,共m次操作,每次操作给一条链上的所有节点分配一个权值,求所有节点被分配到所有的权值里,出现次数最多的权值是多少,如果出现次数相同就输出最小的. (我辣鸡bzoj ...
- 使用tf.ConfigProto()配置Session运行参数和GPU设备指定
参考链接:https://blog.csdn.net/dcrmg/article/details/79091941 tf.ConfigProto()函数用在创建session的时候,用来对sessio ...
- MySQL 面试题(一)
原文地址:http://www.2cto.com/database/201311/254385.html 作者:黄杉(红黑联盟) 公司招聘MySQL DBA面试心得 1 2年MySQL DBA经 ...