Topic Links: Click the open link
Serie A champions:
Specific n long sequences
Given K-long sequence
Ask for LCIs and output this sub-sequence
If there is more than one solution output free solution.
=-= When listening to the sound of the pre-meaning of the song is not thinking clearly, never thought it was over ...
#include <stdio.h> #include <iostream> #include <string.h> #include <set> #include <vector > #include <map> #include <math.h> #include <string> #include <stdlib.h> #include < algorithm>using namespace std; #define N 505int a[n],s[n];int N, k;int dp[n][n];int pre[n][n][2];int is[n][n];vector& Lt;int>g;int Main () {int i,j,co;while (~scanf ("%d", &n) {g.clear (); for (i=1;i<=n;i++) scanf ("%d", &a[i]) ; scanf ("%d", &k), for (i=1;i<=k;i++) scanf ("%d", &s[i]), memset (DP, 0, sizeof DP), memset (pre, 0, sizeof pre); memset (is, 0, sizeof are); for (i=1;i<=n;i++) {int Maxx = 0;int x = 0, y = 0;for (j=1;j<=k;j++) {Dp[i][j] = Dp[i-1][j];if (A[i]>s[j] && Maxx < dp[i-1][j]) {Maxx = Dp[i-1][j];if (Is[i-1][j]) x = i-1, y = j;else {x = Pre[i-1][j][0];y = Pre[i-1][j][1];}} if (A[i]==s[j]) {is[i][j] = 1;dp[i][j] = Maxx + 1;if (Is[x][y]) pre[i][j][0] = x, pre[i][j][1] = y;else {Pre[i][j][0] = Pre[x ][y][0];p re[i][j][1] = pre[x][y][1];} Continue;} if (is[i-1][j]) pre[i][j][0] = i-1, pre[i][j][1] = j;else {pre[i][j][0] = pre[i-1][j][0];p re[i][j][1] = pre[i-1][j][1];}}} int ans = 0;int x = N, y = k;for (i=1;i<=k;i++) if (Ans<dp[n][i]) {ans = Dp[n][i];x = N, y = i;} printf ("%d\n", ans), if (!ans) continue;while (x+y) {if (Is[x][y]) g.push_back (a[x]); int x1 = Pre[x][y][0];int Y1 = pre[x][y ][1]; x = x1, y = y1;} For (I=g.size ()-1; i>=0; i--) {printf ("%d", G[i]), i?printf (""):p UTS ("");}} return 0;} /*21 231 2 3*/
Codeforces 10D LCIs Find the longest common sub and yield increase for this sequence DP