2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:L. The Heaviest Non-decreasing Subsequence Problem

来源:互联网 发布:java object finalize 编辑:程序博客网 时间:2024/06/06 09:41

Let SS be a sequence of integers s_{1}s1s_{2}s2......s_{n}sn Each 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}-10000si10000 . For example, if s_{i}si is 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}si1s_{i2}si2......s_{ik}sik, with i_{1}<i_{2}\ ...\ <i_{k}i1<i2 ... <ik, such that, for all 1 \leq j<k1j<k, we have s_{ij}<s_{ij+1}sij<sij+1.

A heaviest non-decreasing subsequence of SS 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:

8080 7575 7373 9393 7373 7373 1010110101 9797 -11 -11 114114 -11 1011310113 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}2105

Input Format

A list of integers separated by blanks:s_{1}s1s_{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的数变为5个价值为1的数,再求最长上升子序列即可。

#include<bits/stdc++.h>using namespace std;const int MAX = 2e6;int dp[MAX],a[MAX];int main(){int n;char ch;while(scanf("%d%c",&n,&ch)!=EOF){if(ch == '\n'){            if(n<0)puts("0");            else if(n>=10000)puts("5");            else puts("1");continue;}int t=1;if(n >= 10000){a[t++] = n-10000;            a[t++] = n-10000;            a[t++] = n-10000;            a[t++] = n-10000;            a[t++] = n-10000;}else if(n>=0)a[t++] = n;while(scanf("%d%c",&n,&ch)!=EOF){if(n >= 10000){a[t++] = n-10000;a[t++] = n-10000;a[t++] = n-10000;a[t++] = n-10000;a[t++] = n-10000;}else if(n>=0)a[t++] = n;if(ch == '\n')break;}int len = 0;for(int i = 1; i < t; i++){if(len==0||a[i] >=dp[len])dp[++len] = a[i];else{int cnt = upper_bound(dp,dp+1+len,a[i]) - dp;dp[cnt] = a[i];}}printf("%d\n",len);}return 0;}



阅读全文
1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 索尼z3手机忘记开机密码怎么办 索尼忘记锁屏密码怎么办 索尼手机忘记锁屏密码怎么办 忘了手机解锁图案怎么办 索尼手机忘记开机密码怎么办 索尼笔记本开机密码忘了怎么办 手机的开机密码忘了怎么办 联想手机开机密码忘了怎么办 红米note3忘记开机密码怎么办 小米2忘了密码怎么办 小米笔记本电脑忘记开机密码怎么办 小米笔记本忘记开机密码怎么办 小米手机儿童模式忘记密码怎么办 小米应用锁密码忘了怎么办 小米air密码忘了怎么办 小米4密码忘了怎么办 小米手机开机密码忘了怎么办? 小米笔记本电脑开机密码忘了怎么办 小米笔记本开机密码忘了怎么办 htc手机忘记解锁图案怎么办 红米手机屏幕锁定怎么解锁怎么办 小米5s有id怎么办 手机密码找不回来了怎么办? 手机密码图案忘了怎么办 手机屏幕图案锁忘了怎么办 捡到苹果7有id锁怎么办 魅族什么都忘了怎么办 海信电视百事通登陆失败怎么办 去哪儿换号了怎么办 ipan充不进去电怎么办 安卓数据线松了怎么办 索尼z5耳机掉漆怎么办 索尼z5无限重启怎么办 苹果8基带坏了怎么办 oppo手机忘记图案密码怎么办 电池充不进去电怎么办 电脑充不进去电怎么办 苹果5c白苹果怎么办 港行不支持电信卡怎么办 安卓导航不开机怎么办 鞭炮放一半不响怎么办