J Dp
<span style="color:#000099;">/*
___________________________________________________________________________________________
author : Grant Yuan
time : 2014.7.18
algorithm : 最长上升子序列求和 ——————————————————————————————————————————————————————————————————————————————————————————— J - 简单dp 例题扩展
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. 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. Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed. Output
For each case, print the maximum according to rules, and one line one case. Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0 Sample Output
4
10
3
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<algorithm>
using namespace std; int a[100005],n;
int dp[100005]; int main()
{
while(1){
cin>>n;
if(n==0) break;
for(int i=1;i<=n;i++)
cin>>a[i]; memset(dp,0,sizeof(dp));
a[0]=0;
for(int i=1;i<=n;i++){
dp[i]=a[i];
for(int j=1;j<i;j++){
if(a[i]>a[j])
dp[i]=max(dp[i],dp[j]+a[i]);}}
int max=dp[1];
for(int i=1;i<=n;i++)
if(dp[i]>max)
max=dp[i];
cout<<max<<endl;
}
return 0;
}
</span>
J Dp的更多相关文章
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包
J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...
- C. Multiplicity 简单数论+dp(dp[i][j]=dp[i-1][j-1]+dp[i-1][j] 前面序列要满足才能构成后面序列)+sort
题意:给出n 个数 的序列 问 从n个数删去任意个数 删去的数后的序列b1 b2 b3 ......bk k|bk 思路: 这种题目都有一个特性 就是取到bk 的时候 需要前面有个bk-1的序列前 ...
- Andrew Stankevich's Contest (21) J dp+组合数
坑爹的,,组合数模板,,, 6132 njczy2010 1412 Accepted 5572 MS 50620 KB C++ 1844 B 2014-10-02 21:41:15 J - 2-3 T ...
- 牛客集训第七场J /// DP
题目大意: 在矩阵(只有52种字符)中找出所有不包含重复字符的子矩阵个数 #include <bits/stdc++.h> #define ll long long using names ...
- hdu 4049 2011北京赛区网络赛J 状压dp ***
cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...
- 2017 ICPC区域赛(西安站)--- J题 LOL(DP)
题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...
- codeforces gym 100947 J. Killing everything dp+二分
J. Killing everything time limit per test 4 seconds memory limit per test 64 megabytes input standar ...
- icpc 2017北京 J题 Pangu and Stones 区间DP
#1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...
- hdu 3689 杭州 10 现场 J - Infinite monkey theorem 概率dp kmp 难度:1
J - Infinite monkey theorem Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &am ...
随机推荐
- API - 微云
API - 微云 1.接口说明 2.数据上传协议说明 1. 接口说明 文件上传申请,成功会返回实际上传的地址. 根据申请上传返回的地址,组织数据上传. 1.1 URL OAuth2.0协议: http ...
- Java生成目录
Java生成目录 1.说明 推断目录是否存在,假设不存在就创建该目录.并打印其路径.假设存在,打印其路径 2.实现源代码 /** * @Title:BuildFolder.java * @Packag ...
- 【瞎搞】 HDU 3101 The Heart of the Country
比赛时愣是没读懂 题意:有N 个城市 每一个城市都有 val 个 士兵 , 有几条路连接 当敌方攻击你的某个城市时 该城市以及与该城市相连接的城市的士兵总数 要大于 K 不大于 K 该城市就被攻陷.士 ...
- cocos2dx-3.0(1)------win7 32位android环境搭建
參照链接http://blog.csdn.net/wonengxing/article/details/23601359 ----我的生活,我的点点滴滴!! 一. Android工具安装 1. 安装J ...
- hdu2569(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2569 分析: f(n),n个珠子的合格数:a(n),n个珠子,最后2个相同的合格数:b(n),n个珠子 ...
- vmware: The file system upon which * resides is critically low on free space.
The file system upon which ******.localized/Windows XP Professional.vmwarevm' resides is critically ...
- XSS漏洞的分类
XSS漏洞依照攻击利用手法的不同,有下面三种类型: 类型A,本地利用漏洞,这样的漏洞存在于页面中client脚本自身.其攻击步骤例如以下所看到的: Alice给Bob发送一个恶意构造了Web的URL. ...
- wamp mysql 创建主从数据库
这跟你是不是wmap没有关系的, wamp是一个集成环境,只是一次性帮你创建一个web服务器而已 下面给你些配置 一.登录Master服务器,修改my.ini ,添加如下内容: [wampmysqld ...
- 不用Root权限获取已经安装的Apk安装包
在安卓设备上安装的apk都会被保留一份在/data/app目录下,但是该目录对于普通用户来说只有可执行权限,是无法访问的. 但是其子文件具有可读权限. 意思也就说我们直接去查看/data/app这个目 ...
- 深入理解java虚拟机系列(一):java内存区域与内存溢出异常
文章主要是阅读<深入理解java虚拟机:JVM高级特性与最佳实践>第二章:Java内存区域与内存溢出异常 的一些笔记以及概括. 好了開始.假设有什么错误或者遗漏,欢迎指出. 一.概述 先上 ...