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 1075 字典树
#include<stdio.h> #include<iostream> struct node { int num,i; node *a[27]; char s[20];// ...
- Python模块:time、datetime、random、os、sys、optparse
time模块的方法: 时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量. struct_time时间元组,共有九个元素组.如下图: time.localtime([secs]): ...
- Linux rz的使用
RZ是Linux提供的上传的命令,基于XMODEM/YMODEM/ZMODEM协议. 让我们来测试一下参数吧: 先准备一个文件,就叫test.txt吧,内容如下: one line rz -+ 如果 ...
- 可并堆试水--BZOJ1367: [Baltic2004]sequence
n<=1e6个数,把他们修改成递增序列需把每个数增加或减少的总量最小是多少? 方法一:可以证明最后修改的每个数一定是原序列中的数!于是$n^2$DP(逃) 方法二:把$A_i$改成$A_i-i$ ...
- Thinkphp5.0 的使用模型Model更新数据
Thinkphp5.0 的使用模型Model更新数据 (1)使用update()方法进行更新数据 一.where条件写在更新数据中 (这种情况更新的数据,必须含主键) $res = User::upd ...
- 从零开始写STL-内存部分-内存分配器allocator
从零开始写STL-内存部分-内存分配器allocator 内存分配器是什么? 一般而言,c++的内存分配和释放是这样操作的 >>class Foo{ //...}; >>Foo ...
- node+mongodb+win7
一.安装mongodb,参照教程,注意要先启动mongod.exe,再启动mongd.exe.
- 使用go语言实现简单的反向代理工具激活IntelliJ和PyCharm,持续更新
最近Jetbrians系列IDE更新至2017.3版本,激活检测机制也变成了动态封禁域名,导致大部分域名激活被屏蔽了,所以找了下资料,根据ilanyu的代码,改了下地址,实现了本地反向代理激活服务器. ...
- 一个Navi过程下多个DocumentCompleted事件问题的解决的方法
7.16 Marked to Write.... 七月份马克的一篇文章了,今天才想起来把他写完,呵呵. 原本是七月份用来做微博爬虫的,后来发现新浪对机器人的检測不好绕过,连简单地訪问都会被检測出来,后 ...
- Java对话框总结
总结起来非常easy: 1,对话框类型:消息.确认,选项.输入 2,选择图标:错误,信息.警告.问题,无或者自己定义 3,选择消息:字符串,图标.自己定义组件或者他们的集合 4.对于确认对话框,选择选 ...