1. 程式人生 > >The Heaviest Non-decreasing Subsequence Problem

The Heaviest Non-decreasing Subsequence Problem

for def seq lis else i++ stream pro blog

最長非遞減子序列變形題,把大於等於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; }

The Heaviest Non-decreasing Subsequence Problem