Bzoj 3594 Scoi2014 Fampopo wheat Field Tree array

Source: Internet
Author: User

Title effect: Given a sequence, be able to select the number of each part k times and within the range + 1, seek operation after the max value of LIS

My approach is not a standard solution.

。。 5E Why run the complexity of flying.

First of all, the obvious conclusion is that we choose the K right end point is N time to ensure optimal

Knowing this, we'll be able to DP.

F[I][J] indicates the largest LIS with the number of first I ascending J times

Then there's f[i][j]=max{f[k][l]|k<i,l<=j,a[k]+l<=a[i]+j}+1.

To see the three-dimensional partial order can be used in a two-dimensional tree-like array

Time Complexity O (Nklog (max (AI) +k) logk)

The complexity of the flight is really drunk ...

#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;}


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Bzoj 3594 Scoi2014 Fampopo wheat Field Tree array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.