Codeforces 463d gargari and permutations (DP)

Source: Internet
Author: User

Question

 

Refer to ,,,

 

// Find the longest common subsequence of all sequences, // define the State DP [I] as the length of the longest common subsequence of the first I digit in the first sequence, // The state transition equation is DP [I] = max (DP [I], DP [J] + 1 ); j <I // pre-process the positional relationship between two numbers in all sequences. // For example, if two numbers a and B exist in any sequence, as long as a is behind B, after [a] [B] = 1. // If! After [a] [B], the status is transferred. # Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int A [6] [1010]; int after [1010] [1010]; int DP [1010]; int main () {int N, K; scanf ("% d", & N, & K); int II = 0; for (INT I = 0; I <K; I ++) {for (Int J = 0; j <n; j ++) {scanf ("% d ", & A [I] [J]) ;}} memset (after, 0, sizeof (after); memset (DP, 0, sizeof (DP )); for (INT I = 0; I <K; I ++) {for (Int J = 0; j <n; j ++) {for (int K = J + 1; k <n; k ++) {after [A [I] [k] [A [I] [J]] = 1; // K exists after J} int ans = 0; // directly to 1 ~ N status transfer is not allowed // DP for (INT I = 0; I <n; I ++) {DP [I] = 1 according to the first line; for (Int J = 0; j <I; j ++) {If (after [A [0] [J] [A [0] [I] = 0) DP [I] = max (DP [I], DP [J] + 1);} ans = max (DP [I], ANS);} printf ("% d \ n", ANS); Return 0 ;}
View code

 

Codeforces 463d gargari and permutations (DP)

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.