最长上升子序列 nlogn

const LL N = ;
LL num[N];
LL dp[N];
LL go(LL l, LL r, LL k)
{
for (; r >= l; r--)
if (dp[r] <= k)
return r;
return l;
}
LL bins(LL l, LL r, LL k)
{
while (r - l >= )
{
if (r - l <= )
return go(l, r, k);
LL mid = (l + r) >> ;
if (dp[mid] > k)
r = mid;
else
l = mid;
}
}
LL solve(LL n)
{
fill(dp, dp + N, N + );
dp[] = ;
LL ans = ;
for (int i = ; i < n; i++)
{
LL e = num[i];
LL ads = bins(, i, e);
dp[ads + ] = min(dp[ads + ], e);
ans = max(ans, ads+);
}
//cout << ans << endl;
return ans;
}
上一篇:一张图看懂 JS 的事件机制


下一篇:zencart安装后修改configure.php权限