naive dynamic programming routines summary

\ (O (nlogn) \) seek length \ (n-\) is the number of columns of \ (the LIS \)


int LIS(int *a, int n)
{
    
    int *d = new int[n + 5];
    int *g = new int[n + 5];
    for(int i=1; i<=n; ++i) g[i] = INF; // INF = 2147483647
    for(int i=1; i<=n; ++i)
    {
        int k = lower_bound(g+1, g+1+n, a[i]) - g;
        d[i] = k;
        g[k] = a[i];
    }
    
    int ret = 0;
    for(int i=1; i<=n; ++i) ret = max(ret, d[i]);
    return ret;
    
}

will

\ [D (i, j) = min {d (i + 1, j) ~ d (j, j), ..., d (i, j-1) ~ d (i, i), 0} \ ]

Save some part of it, you can optimize the time complexity

Guess you like

Origin www.cnblogs.com/tztqwq/p/12150354.html