Let SSS be a sequence of integers s1s_{1}s​1​​, s2s_{2}s​2​​, ........., sns_{n}s​n​​ Each integer is is associated with a weight by the following rules:

(1) If is is negative, then its weight is 000.

(2) If is is greater than or equal to 100001000010000, then its weight is 555. Furthermore, the real integer value of sis_{i}s​i​​ is si−10000s_{i}-10000s​i​​−10000 . For example, if sis_{i}s​i​​ is 101011010110101, then is is reset to 101101101 and its weight is 555.

(3) Otherwise, its weight is 111.

A non-decreasing subsequence of SSS is a subsequence si1s_{i1}s​i1​​, si2s_{i2}s​i2​​, ........., siks_{ik}s​ik​​, with i1<i2 ... <iki_{1}<i_{2}\ ...\ <i_{k}i​1​​<i​2​​ ... <i​k​​, such that, for all 1≤j<k1 \leq j<k1≤j<k, we have sij<sij+1s_{ij}<s_{ij+1}s​ij​​<s​ij+1​​.

A heaviest non-decreasing subsequence of SSS is a non-decreasing subsequence with the maximum sum of weights.

Write a program that reads a sequence of integers, and outputs the weight of its

heaviest non-decreasing subsequence. For example, given the following sequence:

808080 757575 737373 939393 737373 737373 101011010110101 979797 −1-1−1 −1-1−1 114114114 −1-1−1 101131011310113 118118118

The heaviest non-decreasing subsequence of the sequence is <73,73,73,101,113,118><73, 73, 73, 101, 113, 118><73,73,73,101,113,118> with the total weight being 1+1+1+5+5+1=141+1+1+5+5+1 = 141+1+1+5+5+1=14. Therefore, your program should output 141414 in this example.

We guarantee that the length of the sequence does not exceed 2∗1052*10^{5}2∗10​5​​

Input Format

A list of integers separated by blanks:s1s_{1}s​1​​, s2s_{2}s​2​​,.........,sns_{n}s​n​​

Output Format

A positive integer that is the weight of the heaviest non-decreasing subsequence.

样例输入

80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118

样例输出

14

超过一万的,权重是5,所以把它变成5个就好啦。这样的话问题就转化成了最长不下降子序列~
 #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std; int a[];
int d[]; int main()
{
int x;
int n=;
while(scanf("%d",&x)!=EOF)
{
if (x<) continue;
if (x<) a[++n]=x;
else
for(int i=;i<=;i++) a[++n]=x-;
}
d[]=a[]; //初始化
int len=;
for (int i=;i<=n;i++)
{
if (a[i]>=d[len]) d[++len]=a[i]; //如果可以接在len后面就接上
else //否则就找一个最该替换的替换掉
{
int j=upper_bound(d+,d+len+,a[i])-d; //找到第一个大于它的d的下标
d[j]=a[i];
}
}
printf("%d\n",len);
return ;
}

2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)的更多相关文章

  1. 2017ICPC南宁赛区网络赛 Minimum Distance in a Star Graph (bfs)

    In this problem, we will define a graph called star graph, and the question is to find the minimum d ...

  2. 2017ICPC南宁赛区网络赛 Overlapping Rectangles(重叠矩阵面积和=离散化模板)

    There are nnn rectangles on the plane. The problem is to find the area of the union of these rectang ...

  3. 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)

    You are given a list of train stations, say from the station 111 to the station 100100100. The passe ...

  4. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem【状态压缩】

    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛  M. Frequent Subsets Problem 题意:给定N和α还有M个U={1,2,3,...N}的子集,求子集X个数,X满足:X是U ...

  5. 2017ICPC北京赛区网络赛 Minimum(数学+线段树)

    描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...

  6. 2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)

    描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0 ...

  7. Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)

    参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...

  8. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  9. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

随机推荐

  1. yarn基本命令

    参考文章:https://blog.csdn.net/mjzhang1993/article/details/70092902 1.安装 windows: 下载地址 mac: brew install ...

  2. linux 查看日志命令

    linux中命令cat.more.less均可用来查看文件内容, 区别:cat是一次性显示整个文件的内容,还可以将多个文件连接起来显示,它常与重定向符号配合使用,适用于文件内容少的情况:more和le ...

  3. (二)使用数组长度实现ADT bag(java)

    目录 1.使用固定大小的数组实现ADT bag 包 1.1 一组核心方法 1.2 实现核心方法   1.3 让实现安全 1.4 测试核心方法 1.5 实现更多的方法 1.6 删除项的方法 1.7 测试 ...

  4. ubuntu chmod命令的使用

    我推荐的地址:http://blog.163.com/bluesky_07_06_1/blog/static/164440083201161451735773/ 这个非常的牛逼.

  5. sonar-gerrit plugin配置

    配置 sonar-gerrit plugins stepspre-condition:1. Sonarqube(5.5及以上,本文使用的版本为6.1.3)关于如何安装配置Sonarqube,请参考其他 ...

  6. Mybatis 查询tinyint(1)的数据库字段时会自动转换成boolean类型

    解决方案:将字段的tinyint(1)变成tinyint(2)

  7. FJUT16级第一周寒假作业题解G题

    题目链接:http://210.34.193.66:8080/vj/Contest.jsp?cid=160#P6 涨姿势题1 TimeLimit:1000MS  MemoryLimit:128000K ...

  8. 线程池 execute 和 submit 的区别

    代码示例: public class ThreadPool_Test { public static void main(String[] args) throws InterruptedExcept ...

  9. Linux服务列表(CentOS)

    1.service用法 service SCRIPT COMMAND [OPTIONS] #执行脚本中方法,最常用法 service --status-all #查看所有服务的运行状态 service ...

  10. Mysql索引引起的死锁

    提到索引,首先想到的是效率提高,查询速度提升,不知不觉都会有一种心理趋向,管它三七二十一,先上个索引提高一下效率..但是索引其实也是暗藏杀机的... 今天压测带优化项目,开着Jmeter高并发访问项目 ...