Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23328    Accepted Submission(s): 10266

Problem 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
 /*
时间复杂度O(n^2)
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; typedef __int64 LL;
const int maxn=;
LL dp[maxn],f[maxn];
inline int max(int a,int b){return a>b?a:b;}
int main()
{
int n,i,j;
while(scanf("%d",&n),n)
{
for(i=;i<=n;i++)
{
scanf("%d",f+i);dp[i]=f[i];
}
for(i=;i<=n;i++)
{
for(j=i-;j>;j--)
if(f[i]>f[j])
dp[i]=max(dp[i],dp[j]+f[i]);
}
LL ans=;
for(i=;i<=n;i++)
ans=max(ans,dp[i]);
printf("%I64d\n",ans);
}
return ;
}
 /*
时间复杂度O(nlogn)
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = ;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
int sum[maxn<<];
int a[maxn],b[maxn],c[maxn];
inline int max(int a,int b){return a> b?a:b;} void swap(int &a,int &b){int t=a;a=b;b=t;} void qsort(int l,int r)
{
if(l<r)
{
int t=b[l],i=l,j=r;
while(i!=j)
{
while(b[j]>=t && i<j) j--;
while(b[i]<=t && i<j) i++;
if(i<j) swap(b[i],b[j]);
}
b[l]=b[i];b[i]=t;
qsort(l,i-);
qsort(i+,r);
}
}
int binarysearch(int l,int r,int val)//二分查找,未找到返回-1
{
int mid,ans=-;
while(l<=r)
{
mid=(l+r)>>;
if(val>c[mid]) l=mid+;
else if(val==c[mid]) return mid;
else r=mid-;
}
return ans;
} void build(int l,int r,int rt)
{
sum[rt] = ;
if(l == r)
return ;
int mid = (l + r)>>;
build(lson);
build(rson);
}
void updata(int pos,int v,int l,int r,int rt)
{
if(l == r)
{
sum[rt]=v;
return ;
}
int mid = (l + r)>>;
if(pos <= mid)
updata(pos,v,lson);
else
updata(pos,v,rson);
sum[rt]=(sum[rt<<]>sum[rt<<|]?sum[rt<<]:sum[rt<<|]);
}
int query(int L,int R,int l,int r,int rt)
{
if(L <= l && R >= r)
{
return sum[rt];
}
int mid = (l + r)>>;
int ans;
if(L <= mid)
ans = query(L,R,lson);
if(R > mid)
ans = max(ans,query(L,R,rson));
return ans;
} int main()
{
int n,i;
while(scanf("%d",&n),n)
{
for(i=;i<=n;i++)
{
scanf("%d",a+i);b[i]=a[i];
}
qsort(,n);
int cnt=;c[]=b[];
for(i=;i<=n;i++) if(b[i]!=b[i-])//离散化去重
c[++cnt]=b[i];
build(,cnt,);
int x,maxv,ans=;
for(i=;i<=n;i++)
{
x=binarysearch(,cnt,a[i]);
if(x>)
{
maxv=query(,x-,,cnt,);
updata(x,maxv+a[i],,cnt,);
}
else
{
maxv=;
updata(x,maxv+a[i],,cnt,);
}
if(maxv+a[i]>ans) ans=maxv+a[i];
}
printf("%d\n",ans);
}
return ;
}
 

最新文章

  1. Web Js 按键事件……Enter提交事件 Enter Js事件
  2. Servlet高级
  3. SAP/SD - 做SD你要知道的透明表
  4. Linux: Set OR Change The Library Path
  5. 分布式消息系统Kafka初步
  6. RSA (cryptosystem)
  7. Chapter 2 Open Book——12
  8. 详解Java的自动装箱与拆箱(Autoboxing and unboxing)
  9. MYSQL数据库学习九 数据的操作
  10. java中的异常类型以及区别????
  11. ETCD相关介绍--整体概念及原理方面
  12. JavaScript 深拷贝(deep copy)和浅拷贝(shallow copy)
  13. excel合并
  14. Map集合转成json数据
  15. Java开发环境配置(4)--Maven安装 环境变量配置,本地仓库配置---插件安装
  16. freeswitch源码安装
  17. [转]jQuery选择器 (详解)
  18. SQLserver数据库连接问题
  19. oracle_存储过程小记
  20. Python Web学习笔记之TCP、UDP、ICMP、IGMP的解释和区别

热门文章

  1. prometheus-简介及安装
  2. kubernetes监控-prometheus(十六)
  3. ES6中const的用法
  4. java基础—super关键字
  5. redis的一个bug
  6. NSString 使用 copy、strong
  7. Element表单验证(2)
  8. NOIP模拟赛 经营与开发 小奇挖矿
  9. Spring框架配置文件中有两个相同名字的bean,最后会覆盖掉一个bean
  10. 【dsu || 线段树合并】bzoj4756: [Usaco2017 Jan]Promotion Counting