BZOJ 3594 Scoi2014 方波波麥田 樹陣

來源:互聯網
上載者:User

標籤:

標題效果:給定一個序列,能夠選擇k次每個部分的數量和在範圍內+1,尋求操作後LIS最大值

我的做法是不是一個標準的解決方案。

。。5E為什麼跑飛的複雜性。

。

。

首先,顯而易見的結論是,我們選擇k右端點都是n時才幹保證最優

知道這個我們就能夠DP了- -

令f[i][j]表示前i個數上升j次的最大LIS

那麼有f[i][j]=max{f[k][l]|k<i,l<=j,a[k]+l<=a[i]+j}+1

看到三維偏序就能夠用二維樹狀數組了- -

時間複雜度O(nklog(max(ai)+k)logk)

這複雜度跑的飛起真是醉了。。。

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 10100using namespace std;int n,k,max_num,ans,a[M];namespace BIT{int c[6060][550];void Update(int x,int y,int val){int i,j;for(i=x;i<=max_num+k;i+=i&-i)for(j=y;j<=k+1;j+=j&-j)c[i][j]=max(c[i][j],val);}int Get_Ans(int x,int y){int i,j,re=0;for(i=x;i;i-=i&-i)for(j=y;j;j-=j&-j)re=max(re,c[i][j]);return re;}}int main(){using namespace BIT;int i,j;for(cin>>n>>k,i=1;i<=n;i++){scanf("%d",&a[i]);max_num=max(max_num,a[i]);}for(i=1;i<=n;i++)for(j=k;~j;j--){int temp=Get_Ans(a[i]+j,j+1)+1;ans=max(ans,temp);Update(a[i]+j,j+1,temp);}cout<<ans<<endl;return 0;}


著作權聲明:本文部落格原創文章。部落格,未經同意,不得轉載。

BZOJ 3594 Scoi2014 方波波麥田 樹陣

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.