The Heaviest Non-decreasing Subsequence Problem

最长非递减子序列变形题,把大于等于10000的copy五次放回去就可以了

ac代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
const LL N=200105;
int a[N];
int dp[N];
int LIS(int a[],int len)
{
    int dlen=1;
    memset(dp,0,sizeof(dp));
    dp[0]=a[0];//
    for(int i=1;i<len;i++)
    {
        if(a[i] < dp[0]) // 最开始的位置
        {
            dp[0]=a[i];
            continue;
        }
        if(a[i] >= dp[dlen-1])
        {
            dp[dlen++]=a[i];// new insert
        }
        else
        {
            int pos=upper_bound(dp,dp+dlen,a[i])-dp;//
            dp[pos]=a[i];
        }
    }
    return dlen;
}
int main()
{
    int len=0;
    int x;
    while(~scanf("%d",&x))
    {
        if(x<0) continue;
        if(x>=10000)
        {
            x-=10000;
            for(int i=1;i<=5;i++) a[len++]=x;
        }
        else a[len++]=x;
    }
    /*
    for(int i=1;i<=14;i++)
    {
        scanf("%d",&x);
        if(x<0) continue;
        if(x>=10000)
        {
            x-=10000;
            for(int i=1;i<=5;i++) a[len++]=x;
        }
        else a[len++]=x;
    }
    */
  //  for(int i=1;i<=len;i++) cout<<a[i]<<‘ ‘;
  //  cout<<endl;
    cout<<LIS(a,len)<<endl;
    return 0;
}
时间: 2024-11-15 06:36:12

The Heaviest Non-decreasing Subsequence Problem的相关文章

SPOJ LIS2 Another Longest Increasing Subsequence Problem 三维偏序最长链 CDQ分治

Another Longest Increasing Subsequence Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19929 Description Given a sequence of N pairs of integers, find the length of the longest incre

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 10000100001

Longest Common Subsequence Problem

The longest common subsequence (LCS) problem is the problem of finding the longest subsequence common to all sequences in a set of sequences (often just two sequences). It differs from problems of finding common substrings: unlike substrings, subsequ

[Algorithms] Using Dynamic Programming to Solve longest common subsequence problem

Let's say we have two strings: str1 = 'ACDEB' str2 = 'AEBC' We need to find the longest common subsequence, which in this case should be 'AEB'. Using dynamic programming, we want to compare by char not by whole words. we need memo to keep tracking th

SPOJ:Another Longest Increasing Subsequence Problem(CDQ分治求三维偏序)

Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it. An increasing sequence A1..An is a sequence such that for every i < j, Ai < Aj. A subsequence of a sequence is a sequence that appears in the same

SPOJ - LIS2 Another Longest Increasing Subsequence Problem

cdq分治,dp(i)表示以i为结尾的最长LIS,那么dp的递推是依赖于左边的. 因此在分治的时候需要利用左边的子问题来递推右边. (345ms? 区间树TLE /********************************************************* * ------------------ * * author AbyssFish * **********************************************************/ #inclu

@atcoder - [email&#160;protected] Simple Subsequence Problem

目录 @[email protected] @[email protected] @accepted [email protected] @[email protected] @[email protected] 给定由若干长度 <= N 的 01 字符串组成的集合 S.请找到长度最长的串 t(如果有多个选字典序最小的),使得存在 >= K 个 S 中的字符串,使得 t 是这些字符串的子序列. 原题题面. @[email protected] 先看看怎么检验串 t 是否为某个串 s 的子序列:

[GeeksForGeeks] Longest Bitonic Subsequence

Given an array arr[0.....n-1] containing n positive integers, find the length of the longest bitonic subsequence. A subsequence of arr[] is called Bitonic if it is first increasing, then decreasing. Analysis: This problem is a variation of the standa

WOJ 1047 LCS problem (LCS 算法总结 )

http://acm.whu.edu.cn/land/problem/detail?problem_id=1047 Description Recently, Flymouse reads a book about Algorithm and Data Structure. The book reads: there are two types of LCS Problems. One is Longest Common Subsequence problem. By the way of Dy