Vijos1264: A mysterious spell

Source: Internet
Author: User

Describe

As a high-ranking spy on the moon, your task is always to push you to the top. For example, this time, worship the bishop sent you to follow Zhaolinger line, dive into the bottom of the trial.

It is said that the trial of the bottom of the cave hidden Five elements of the highest magic spell: The Winds, Thunder, Snow Demon, Vulcan, the Curse of the mountain God. In order to acquire these spells, it takes a lot of hard work, but the return is also very rich.

Pray you tell him how long the spell is. (You: "Would you like to know the exact contents of the spell?") "Worship the Moon:" Think, but Vijos does not support special judge. "-_-The original Big man also has the sad ... )
So you snuck aside and wanted to take a look at what the spell was. Suddenly, the sky (?? Test the bottom of the cave to see the sky?? There are two very long strings of numbers, and you're freaking out. Which is the real mantra? It suddenly occurred to you that neither of these were spells (perhaps called pseudo-spells), and that the true mantra was closely related to them. So you open the note that was written to you by the month of worship: "The Real incantation is their Common increasing subsequence of maximal Possible Length"
"Damn it, it's going to be e-wen!" You curse, but in order to borns life, but also have to work hard to calculate the length of the spell.

Format input Format

The first behavior is 1 number n, which represents the n set of test data.

For each set of test data, a two-digit string is described, first a number is a pseudo-mantra length m, and the next m number describes the content of the pseudo-mantra.

Output format

A total of n rows, one number per line, describing the length of the corresponding mantra.

Sample input:

1
5 1 4) 2 5-12
4-12 1 2 4

Sample output:

2

Idea: The public longest ascending subsequence.

#include <iostream>#include<string.h>using namespaceStd;typedefLong Longll;Const intmaxn=505;intN,m;ll A[MAXN],B[MAXN];intDP[MAXN];intMain () {intT; CIN>>u;  while(t--) {memset (DP,0,sizeof(DP)); CIN>>N;  for(intI=0; i<n;i++) Cin>>A[i]; CIN>>m;  for(intI=0; i<m;i++) Cin>>B[i]; intres=0;  for(intI=0; i<n;i++)            {            intmx=0;  for(intj=0; j<m;j++)            {                if(B[j]<a[i]) mx=Max (mx,dp[j]); if(B[j]==a[i]) dp[j]=mx+1; Res=Max (res,dp[j]); }} cout<<res<<Endl; }    return 0;}

Vijos1264: A mysterious spell

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.