Codeforces 10D. LCIs Longest public Ascent sub-series template title + Print path

Source: Internet
Author: User

Recommend a fried chicken to praise the blog.

The following code has the print path.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < cstdio> #include <queue> #include <cmath> #include <stack> #include <map> #include <ctime > #include <iomanip> #pragma comment (linker, "/stack:1024000000"); #define EPS (1e-6) #define LL Long Long#define ULL unsigned long long#define _ll __int64#define INF 0x3f3f3f3f#define Mod 1000000007using namespace Std;int a[510],b[510] ; int py[510][510],px[510][510],dp[510][510] = {0};void Output (int x,int y) {if (x = =-1 && y = =-1) retur    n;    Output (Px[x][y],py[x][y]); if (a[x] = = B[y]) printf ("%d", a[x]);}    int main () {int n,m,i,j,mlen,x,y;    scanf ("%d", &n);    for (i = 1;i <= n; ++i) scanf ("%d", &a[i]);    scanf ("%d", &m);    for (i = 1;i <= m; ++i) scanf ("%d", &b[i]);    int Max = 0,ax,ay;        for (i = 1;i <= n; ++i) {Mlen = 0,x = -1,y =-1; for (j = 1;j <= m; ++j) {           DP[I][J] = Dp[i-1][j];            PX[I][J] = i-1,py[i][j] = j;            if (B[j] < A[i] && Dp[i-1][j] > Mlen) mlen = Dp[i-1][j],x = I-1,y = j;            if (b[j] = = A[i]) dp[i][j] = Mlen + 1,px[i][j] = x,py[i][j] = y;        if (Dp[i][j] > max) max = Dp[i][j],ax = I,ay = j;    }} if (max) printf ("%d\n", Max), Output (Ax,ay);    else printf ("0\n"); return 0;}

Codeforces 10D. LCIs Longest public Ascent sub-series template title + Print path

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.