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