The Heaviest Non-decreasing Subsequence Problem(2017南宁网络赛)
来源:互联网 发布:赚微信红包软件 编辑:程序博客网 时间:2024/05/20 04:10
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 00.
(2) If is is greater than or equal to 1000010000, then its weight is 55. Furthermore, the real integer value of sis_{i}si is si−10000s_{i}-10000. For example, if sis_{i}si is 1010110101, then is is reset to 101101and its weight is 55.
(3) Otherwise, its weight is 11.
A non-decreasing subsequence of SSS is a subsequence si1s_{i1},si2s_{i2},.........,siks_{ik}, with i1<i2 ... <iki_{1}<i_{2}\ ...\ <i_{k}i1<i2 ... <ik, such that, for all 1≤j<k1 \leq j<k, we have sij<sij+1 s_{ij}<s_{ij+1<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:
8080757737393937373737310101101019797−1-1−1-1114114−1-11011310113118118
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 141414 in this example.
We guarantee that the length of the sequence does not exceed2∗1052*10^{5}。
Input Format
A list of integers separated by blanks:s1s_{1}s1,s2s_{2}s2,.........,sns_{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
//题意:给定一个数组,现规定,里面的数值为负的话,它的weight是0,若大于等于0且小于10000的话,其weight为1,若大于等于10000,它的weight为5,且它的值是原来的值减10000。求这个数组的子串中weight和的最大值。
//思路:开一个新数组,遍历给定的数组,值为负的直接舍去,若值是小于10000的非负数,就依次存到一个新数组,若值大于10000,将这个值减去10000后,放入新数组中,放5次,因为它的weught=5,然后就得到一个新数组,求这个新数组的非递减最长子序列的长度即可。
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <cmath>#include <vector>#include <queue>#include <algorithm>using namespace std;const int MAX=2e5+100;int num[MAX];int a[MAX];int dp[MAX];int cnt;int bsearch(int len,int x){ int l=0,r=len-1; while(l<=r) { int mid=(l+r)/2; if(x>=dp[mid-1]&&x<dp[mid])return mid; else if(x<dp[mid-1])r=mid-1; else l=mid+1; } return l;}//最长非递减子序列int LIS(){ dp[0]=a[0]; int len=1; int j; for(int i=1; i<cnt; i++) { if(a[i]<dp[0])j=0; else if(a[i]>=dp[len-1])j=len++; else j=bsearch(len,a[i]); dp[j]=a[i]; } return len;}int main(){ memset(num,0,sizeof(num)); memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); int nn=0; while(scanf("%d",&num[nn])!=EOF) { nn++; } cnt=0; for(int i=0;i<nn;i++) { if(num[i]<0) continue; if(num[i]>=10000) { num[i]-=10000; for(int j=0;j<5;j++) { a[cnt++]=num[i]; } } else { a[cnt++]=num[i]; } } int ans=LIS(); printf("%d\n",ans); return 0;}
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- The Heaviest Non-decreasing Subsequence Problem(2017南宁网络赛)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem (LIS)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛-L. The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:L. The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem 最长不下降序列
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem
- The Heaviest Non-decreasing Subsequence Problem 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 常见问题
- 计蒜客 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017南宁网络赛L.The Heaviest Non-decreasing Subsequence Problem (最长非递减子序列)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L.The Heaviest Non-decreasing Subsequence Problem
- 最长不减子序列变形 The Heaviest Non-decreasing Subsequence Problem 南宁网络赛
- 2017 icpc 南宁赛区 L.The Heaviest Non-decreasing Subsequence Problem(LIS)
- The Heaviest Non-decreasing Subsequence Problem ACM-ICPC南宁wa
- 2017年9月24日训练总结
- Java中StringBuffer方法
- ServletContext及其相关方法
- caioj1064 最长上升子序列
- Python3:urllib中urlopen()函数新特点
- The Heaviest Non-decreasing Subsequence Problem(2017南宁网络赛)
- “麦迪网杯”擂台赛
- 第三周项目一 (1)
- gawk
- 自定义控件的讲解
- vs2015+openCV(x64)出现运行时”无法查找或打开 PDB 文件”问题
- 江苏科技大学“FlySpiders”本创小组组员学习记录——周云
- 线段树 求一个序列的非递增子序列的权值和的最大值
- 树的重量