2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)

Let SSS be a sequence of integers s1s_{1}s?1??, s2s_{2}s?2??, ........., sns_{n}s?n?? Each integer is is associated with a weight by the following rules:

(1) If is is negative, then its weight is 000.

(2) If is is greater than or equal to 100001000010000, then its weight is 555. Furthermore, the real integer value of sis_{i}s?i?? is si−10000s_{i}-10000s?i??−10000 . For example, if sis_{i}s?i?? is 101011010110101, then is is reset to 101101101 and its weight is 555.

(3) Otherwise, its weight is 111.

A non-decreasing subsequence of SSS is a subsequence si1s_{i1}s?i1??, si2s_{i2}s?i2??, ........., siks_{ik}s?ik??, with i1<i2 ... <iki_{1}<i_{2}\ ...\ <i_{k}i?1??<i?2?? ... <i?k??, such that, for all 1≤j<k1 \leq j<k1≤j<k, we have sij<sij+1s_{ij}<s_{ij+1}s?ij??<s?ij+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:

808080 757575 737373 939393 737373 737373 101011010110101 979797 −1-1−1 −1-1−1 114114114 −1-1−1 101131011310113 118118118

The heaviest non-decreasing subsequence of the sequence is <73,73,73,101,113,118><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 = 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 exceed 2∗1052*10^{5}2∗10?5??

Input Format

A list of integers separated by blanks:s1s_{1}s?1??, s2s_{2}s?2??,.........,sns_{n}s?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

超过一万的,权重是5,所以把它变成5个就好啦。这样的话问题就转化成了最长不下降子序列~
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5
 6 int a[2000005];
 7 int d[2000005];
 8
 9 int main()
10 {
11     int x;
12     int n=0;
13     while(scanf("%d",&x)!=EOF)
14     {
15        if (x<0) continue;
16        if (x<10000) a[++n]=x;
17          else
18         for(int i=1;i<=5;i++) a[++n]=x-10000;
19     }
20     d[1]=a[1];  //初始化
21     int len=1;
22     for (int i=2;i<=n;i++)
23     {
24         if (a[i]>=d[len]) d[++len]=a[i];  //如果可以接在len后面就接上
25         else  //否则就找一个最该替换的替换掉
26         {
27             int j=upper_bound(d+1,d+len+1,a[i])-d;  //找到第一个大于它的d的下标
28             d[j]=a[i];
29         }
30     }
31     printf("%d\n",len);
32     return 0;
33 }
时间: 2024-10-05 04:03:23

2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)的相关文章

2017ICPC北京赛区网络赛 Minimum(数学+线段树)

描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. Output Minx,y∈[l,r] {ax?ay}. 2. Let ax=y. 输入 The first line is an integer T, indicating the number of test cases. (1≤T≤10). For each test case: The fi

2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)

描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, …, n-1. He plans to spend m consecutive days(2 ≤ m ≤ n)in Beijing. During these m days, he intends to use the first day and another day to vis

ICPC 2018 徐州赛区网络赛

ACM-ICPC 2018 徐州赛区网络赛 ?去年博客记录过这场比赛经历:该死的水题 ?一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. ? ? D. Easy Math 题意: ? 给定 \(n\), \(m\) ,求 \(\sum _{i=1}^{m} \mu(in)\) .其中 $ 1 \le n \le 1e12$ , $ 1 \le m \le 2e9$ ,\(\mu(n)\) 为莫比乌斯函数. ? 思路: ? 容易知道,\(i\) 与 \(n\) 不互质时, \(\m

HDU 5875 Function -2016 ICPC 大连赛区网络赛

题目链接 网络赛的水实在太深,这场居然没出线zzz,差了一点点,看到这道题的的时候就剩半个小时了.上面是官方的题意题解,打完了才知道暴力就可以过,暴力我们当时是想出来了的,如果稍稍再优化一下估计就过了zzz.去年有一场现场赛也是n=1000,n^3过了,看来关键时刻实在做不出来就得大胆暴力啊. #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+5; int a[maxn]

ACM-ICPC 2018 徐州赛区(网络赛)

A. Hard to prepare After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle. There are

2014 ACM/ICPC 鞍山赛区网络赛(清华命题)

为迎接10月17号清华命题的鞍山现场赛 杭电上的题目 Biconnected(hdu4997)      Rotate(hdu4998)     Overt(hdu4999)   Clone(hdu5000)   Walk(hdu5001)   LianLianKan   Rescue   Spy's Work   Color the Tree   The Ghost Blows Light   USACO ORZ   2013/8/27

HDU5006 Resistance (2014年鞍山赛区网络赛J题)

1.题目描述:点击打开链接 2.解题思路:本题利用缩点+高斯消元解决.本题的最大特点就是电阻非零即一,如果电阻为0,说明零点之间是等电位点,可以看做一个整体,自然可以想到先利用并查集进行缩点操作,将复杂的电路图转化为不相等的电位点构成的电路图.如果转换完毕后,发现s和t在一个集合中,说明两点之间是等电位的,等效电阻为0,否则,对转换后的图G'重新判断连通性,依然可以利用并查集解决,如果发现不连通,说明s与t之间开路,电阻为inf,否则,就可以根据tot个点的电位列写方程. 我们令有1A的电流从点

hdu 4041 2011北京赛区网络赛F 组合数+斯特林数 ***

插板法基础知识 斯特林数见百科 1 #include<iostream> 2 #include<cmath> 3 #include<cstdio> 4 #include<cstring> 5 #define LL long long 6 #define eps 1e-7 7 #define MOD 1000000007 8 using namespace std; 9 int c[2001][2001]={1},stir2[1005][1005]={1};

hdu 4033 2011成都赛区网络赛 余弦定理+二分 **

二分边长,判断最后内角和是否为2pi,注意l与r的选取,保证能组成三角形 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 10000