2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)
Let SSS be a sequence of integers s1s_{1}s1, s2s_{2}s2, ........., sns_{n}sn 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}si is si−10000s_{i}-10000si−10000 . For example, if sis_{i}si 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}si1, si2s_{i2}si2, ........., siks_{ik}sik, with i1<i2 ... <iki_{1}<i_{2}\ ...\ <i_{k}i1<i2 ... <ik, such that, for all 1≤j<k1 \leq j<k1≤j<k, we have sij<sij+1s_{ij}<s_{ij+1}sij<sij+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∗105
Input Format
A list of integers separated by blanks:s1s_{1}s1, s2s_{2}s2,.........,sns_{n}sn
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 (最长不下降子序列)的更多相关文章
- 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 ...
- 2017ICPC南宁赛区网络赛 Overlapping Rectangles(重叠矩阵面积和=离散化模板)
There are nnn rectangles on the plane. The problem is to find the area of the union of these rectang ...
- 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)
You are given a list of train stations, say from the station 111 to the station 100100100. The passe ...
- 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 ...
- 2017ICPC北京赛区网络赛 Minimum(数学+线段树)
描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...
- 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 ...
- Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)
参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
随机推荐
- flexbox与grid layout的区别
flexbox是一种针对一维的局部布局,以轴为核心的弹性布局. grid layout是二维的更加全面的网格布局,
- js异常处理
<script> function myFunction() { try { var x=document.getElementById("demo").value; ...
- js 异步加载
document 加载 document.write("<scr" + "ipt src=\"js/jquery.js\"></sc ...
- Echarts 简单报表系列一:柱状图
见代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- 五、持久层框架(Hibernate)
一.分页查询 使用Criteria进行分页查询,无论是使用Oracle,MySQL,NoSQL,DB2,分页查询的代码写法都相同. 分页查询代码示例: package com.demo.test; i ...
- Jquery中.attr()和.data()的区别
$.attr()和$.data()本质上属于DOM属性和Jquery对象属性的区别. 一个简单的例子 <!DOCTYPE html> <html> <head> & ...
- 搜索路径---PYTHONPATH 变量
- 方便好用的 Idea mybatis 插件 MyBatisCodeHelper
优点: 1.mapper文件(即表对应的dao)与xml文件自由切换,方便代码评审: 2.自动代码生成功能提高开发效率,mysql数据库创建好表结构,写完 pojo(注意字段类型要统一用对象类型!), ...
- Neo4J 教程
好文转载: W3C: https://www.w3cschool.cn/neo4j/neo4j_cypher_api_example.html neo4j图数据库入门: http://blog.csd ...
- java有关构造器的面试题详解
1,编译器只会提供自动提供一个默认的无参数的构造函数 2,如果程序员没有给类A没有提供构造函数,则编译器会自动提供一个默认的无参数的构造函数,如果用户提供了自己的构造函数,则编译器就不在提供默认的无参 ...