Uva 111-history Grading (DP/LCS)

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions pit. Originally a look at the bare LCS, but the input in the title is not the original sequence, but the original sequence, but the position of the original sequence. For example 3 1 2 is not s[1]=3 but 1 in the sequence position is 3 i.e. s[3]=1; (s[x]=i;)

Then enter the processing on the bare LCS.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1<<12#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int> #define ull unsigned long lon Gusing namespace Std;short dp[22][22];int s[22],t[22],n;void solve () {memset (dp,0,sizeof (DP)); for (int i=1;i<=n;i++ ) for (int j=1;j<=n;j++) if (S[i]==t[j]) Dp[i][j]=dp[i-1][j-1]+1;elsedp[i][j]=max (dp[i][j-1],dp[i-1][j]);p rintf (" %d\n ", Dp[n][n]);} int main () {int x;while (~scanf ("%d", &n)) {for (int i=1;i<=n;i++) {scanf ("%d", &x); s[x]=i;} while (~SCANF ("%d", &x)) {t[x]=1;for (int i=2;i<=n;i++) {scanf ("%d", &x); t[x]=i;}    Solve ();}} return 0;}

Uva 111-history Grading (DP/LCS)

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.