2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
Let SS be
a sequence of integers s_{1}s1, s_{2}s2, ......, s_{n}snEach
integer is is associated with a weight by the following rules:
(1) If is is negative, then its weight is 00.
(2) If is is greater than or equal to 1000010000,
then its weight is 55.
Furthermore, the real integer value of s_{i}si is s_{i}-10000si−10000 .
For example, if s_{i}siis 1010110101,
then is is reset to 101101 and
its weight is 55.
(3) Otherwise, its weight is 11.
A non-decreasing subsequence of SS is
a subsequence s_{i1}si1, s_{i2}si2, ......, s_{ik}sik,
with i_{1}<i_{2}\
...\ <i_{k}i1<i2 ... <ik,
such that, for all 1
\leq j<k1≤j<k,
we have s_{ij}<s_{ij+1}sij<sij+1.
A heaviest non-decreasing subsequence of SSis
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:
8080 7575 7373 9393 7373 7373 1010110101 9797 -1−1 -1−1 114114 -1−11011310113 118118
The heaviest non-decreasing subsequence of the sequence is <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=14.
Therefore, your program should output 1414 in
this example.
We guarantee that the length of the sequence does not exceed 2*10^{5}2∗105
Input Format
A list of integers separated by blanks:s_{1}s1, s_{2}s2,......,s_{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的数分成五个权值为1的数,只需要把权值为5的数连写5个,这样就转化为求最长上升子序列的长度了。
先预处理,所有负数全部去掉,因为如果负数在序列前面,会使最长上升子序列的长度增加,然后把值大于等于10000的数减去10000,连写5次,求最长上升子列的长度即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1e6+10;
int temp[MAXN],a[MAXN], c[MAXN], n;
int bin(int size, int k)
{
int l = 1, r = size;
while (l <= r)
{
int mid = (l + r) / 2;
if (k>=c[mid]) //升序
l = mid + 1;
else
r = mid - 1;
}
return l;
}
int LIS()
{
int i, j, cnt = 0, k;
for (i = 1; i <= n; i++)
{
if (cnt == 0 || a[i]>=c[cnt]) //升序
c[++cnt] = a[i];
else
{
k = bin(cnt, a[i]);
c[k] = a[i];
}
}
return cnt;
}
int main()
{
// freopen("in.txt","r",stdin);
int t=1,i;
while (scanf("%d", &temp[t++])!=EOF);
n=t--;
//预处理
for(i=1,t=1;i<=n;i++)
{
if(temp[i]>=10000)
{
a[t++]=temp[i]-10000;
a[t++]=temp[i]-10000;
a[t++]=temp[i]-10000;
a[t++]=temp[i]-10000;
a[t++]=temp[i]-10000;
}else if(temp[i]>=0)
a[t++]=temp[i];
else
continue;
}
n=t--;
int tem = LIS();
cout<<tem<<endl;
return 0;
}
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem的更多相关文章
- 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 ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- 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 i ...
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- ICPC 2018 徐州赛区网络赛
ACM-ICPC 2018 徐州赛区网络赛 去年博客记录过这场比赛经历:该死的水题 一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. D. Easy Math 题意: ...
- Skiing 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题(拓扑序求有向图最长路)
参考博客(感谢博主):http://blog.csdn.net/yo_bc/article/details/77917288 题意: 给定一个有向无环图,求该图的最长路. 思路: 由于是有向无环图,所 ...
- [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题
第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...
- 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit 1000 ms Memory li ...
- 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!
鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS Memory Limit:262144KB 64bit IO Fo ...
- 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 ...
随机推荐
- hdu 3657 最小割(牛逼!!!!)总算理解了
<strong></strong> 转载:http://blog.csdn.net/me4546/article/details/6662959 加颜色的太棒了!!! 在网上看 ...
- java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.views.login_jsp
背景:SpringBoot的项目配置了对jsp的支持,走控制器就报这个错误.相关配置如下: <!-- JSP BEGIN --> <dependency> <groupI ...
- Inversion 归并求逆元
bobo has a sequence a 1,a 2,…,a n. He is allowed to swap twoadjacent numbers for no more than k time ...
- POJ 2686_Traveling by Stagecoach【状态压缩DP】
题意: 一共有m个城市,城市之间有双向路连接,一个人有n张马车票,一张马车票只能走一条路,走一条路的时间为这条路的长度除以使用的马车票上规定的马车数,问这个人从a出发到b最少使用时间. 分析: 状态压 ...
- 修改mysql root用户密码(忘记密码)
vi /etc/my.cnf,在[mysqld]中添加 skip-grant-tables 例如: [mysqld] skip-grant-tables datadir=/var/lib/mysql ...
- intellij使用tomcat搭建servlet运行时环境
http://suiyu.online/2017/08/01/intellij%E4%BD%BF%E7%94%A8tomcat%E6%90%AD%E5%BB%BAservlet%E8%BF%90%E8 ...
- zabbix学习系列之基础概念
触发器 概念 "监控项"仅负责收集数据,而通常收集数据的目的还包括在某指标对应的数据超出合理范围时给相关人员发送警告信息,"触发器"正式英语为监控项所收集的数据 ...
- python的字典有些类似js对象
python的字典有些类似js对象 dict1 = {} dict1['one']= '1-one' dict1[2] = '2-tow' tinydict = {'name':'tome','cod ...
- oracle initialization or shutdown in progress 问题解决
今天登录oracle时遇到oracle initialization or shutdown in progress 这个错误提示,在网上搜了下,试了非常多方法,最后结合几种方法结合,成功攻克了问题! ...
- 10.11无法打开Xcode6.4的解决方法
前言 mac升级到10.11版本号并安装Xcode7.0Beta之后,Dock中的Xcode6.3图标上出现一个禁止符号,打开提示到App store更新最新版本号,更新到6.4之后问题依然,还是提示 ...