我是靠谱客的博主 受伤绿茶,这篇文章主要介绍The Heaviest Non-decreasing Subsequence Problem(2017南宁网络赛),现在分享给大家,希望可以做个参考。

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.

样例输入

复制代码
1
80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118

样例输出

复制代码
1
14


//题意:给定一个数组,现规定,里面的数值为负的话,它的weight是0,若大于等于0且小于10000的话,其weight为1,若大于等于10000,它的weight为5,且它的值是原来的值减10000。求这个数组的子串中weight和的最大值。


//思路:开一个新数组,遍历给定的数组,值为负的直接舍去,若值是小于10000的非负数,就依次存到一个新数组,若值大于10000,将这个值减去10000后,放入新数组中,放5次,因为它的weught=5,然后就得到一个新数组,求这个新数组的非递减最长子序列的长度即可。


复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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("%dn",ans); return 0; }


最后

以上就是受伤绿茶最近收集整理的关于The Heaviest Non-decreasing Subsequence Problem(2017南宁网络赛)的全部内容,更多相关The内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(93)

评论列表共有 0 条评论

立即
投稿
返回
顶部