And I encountered a wonderful code.
I was able to solve the problem, but the sample code in my textbook was so great. I was thrilled!!
Here's the source code.
In this manner, You can solve LIS at the order of nlog(n).
Notice that the STL function lower_bound() works at log(n) since the internal structure is a binary tree.
#define MAX_N 64
int x[] = {4, 2, 3, 1, 5};
int dp[MAX_N];
int main() {
fill(dp, dp+MAX_N, INF);
REP(i, SIZE(x))
*lower_bound(dp, dp+MAX_N, x[i]) = x[i];
cout << lower_bound(dp, dp+MAX_N, INF) - dp << endl;
}
0 件のコメント:
コメントを投稿