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. python-mongodb基本操作都在这了

    数据库 增 use db1 #有则切换,无则新增 查 show dbs #查看所有 db #当前 删 db.dropDatabase() 集合: 增: db.user db.user.info db. ...

  2. Oracle.练习题

    2018-07-31 ---练习3 ---创建sporter表 create table sporter( sporterid ) constraint sport_id primary key, s ...

  3. 你应该这样理解JVM内存管理

    在进行Java程序设计时,一般不涉及内存的分配和内存回收的相关代码,此处引用一句话: Java和C++之间存在一堵由内存动态分配和垃圾收集技术所围成的高墙,墙外的人想进去,墙里面的人想出来 ,个人从这 ...

  4. js作用域及闭包

    作用域 执行环境是js最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了它们各自的行为. 1.全局执行环境就是最外围的一个执行环境,每一个函数都有自己的作用域 2.简单的说局部作用 ...

  5. el表达式原样输出,不被解析

    今天遇到了,在jar包都有的前提下EL表达式原样输出,不被解析,原因是: page指令中确少 isELIgnored="false" 加上就好了 <%@ page langu ...

  6. 深入理解java虚拟机---虚拟机工具jconsole(十八)

    Jconsole,Java Monitoring and Management Console. Jconsole是JDK自带的监控工具,在JDK/bin目录下可以找到.它用于连接正在运行的本地或者远 ...

  7. session会话示例

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  8. DevExpress WinForms v18.2新版亮点(一)

    行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress WinForms v1 ...

  9. 【PyImageSearch】Ubuntu16.04使用OpenCV3.3.0实现图像分类

    这篇博文将会展示如何采用一个预训练的深度学习网络(模型)在ImageNet的数据集并把它当作输入图像. 首先说明,运行环境为Ubuntu16.04(或者MacOS),windows暂不支持,已经编译好 ...

  10. DOM&BOM

    文档对象模型(Document Object Model) 来源:文档对象模型(Document Object Model)的历史与20世纪90年代末Netscape Navigator和Micros ...