Uva10192-Vacation

Source: Internet
Author: User
# Include <iostream> # include <map> # include <string> # include <cstring> # include <cstdio> # include <cstdlib> # include <cmath> # include <queue> # include <vector> # include <algorithm> using namespace std; int dp [110] [110]; int main () {int I, j, n, m, cs = 0; string a, B; while (getline (cin, a) {if (a = "#") break; getline (cin, B); n =. length (); m = B. length (); memset (dp, 0, sizeof (dp); for (I = 1; I <= n; I ++) for (j = 1; j <= m; j + +) if (a [i-1] = B [j-1]) dp [I] [j] = dp [i-1] [j-1] + 1; elsedp [I] [j] = max (dp [i-1] [j], dp [I] [j-1]); printf ("Case # % d: you can visit at most % d cities. \ n ", ++ cs, dp [n] [m]);} return 0 ;}

Problem E: Vacation

The Problem

You are planning to take some rest and to go out on vacation, but you really don't know which cities you shoshould visit. So, you ask your parents for help. Your mother says"My son, you MUST visit Paris, Madrid, Lisboa and London. But it's only fun in this order ."Then your father says:"Son, if you're planning to travel, go first to Paris, then to Lisboa, then to London and then, at last, go to Madrid. I know what I'm talking about."

Now you're a bit confused, as you didn't expected this situation. you're afraid that you'll hurt your mother if you follow your father's suggestion. but you're also afraid to hurt your father if you follow you mother's suggestion. but it can get worse, because you can hurt both of them if you simply ignore their suggestions!

Thus, you decide that you'll try to follow their suggestions in the better way that you can. so, you realize that the "Paris-Lisboa-London" order is the one which better satisfies both your mother and your father. afterwards you can say that you cocould not visit Madrid, even though you wo'd 've liked it very much.

If your father have suggested the "London-Paris-Lisboa-Madrid" order, then you wowould have two orders, "Paris-Lisboa" and "Paris-Madrid ", that wocould better satisfy both of your parent's suggestions. in this case, you cocould only visit 2 cities.

You want to avoid problems like this one in the future. And what if their travel suggestions were bigger? Probably you wocould not find the better way very easy. so, you decided to write a program to help you in this task. you'll represent each city by one character, using uppercase letters, lowercase letters, digits and the space. thus, you can have at most 63 different cities to visit. but it's possible that you'll visit some city more than once.

If you represent Paris with "a", Madrid with "B", Lisboa with "c" and London with "d ", then your mother's suggestion wocould be "abcd" and you father's suggestion wocould be "acdb" (or "dacb", in the second example ).

The program will read two travel sequences and it must answer how many cities you can travel to such that you'll satisfy both of your parents and it's maximum.

The Input

The input will consist on an arbitrary number of city sequence pairs. the end of input occurs when the first sequence starts with an "#" character (without the quotes ). your program shocould not process this case. each travel sequence will be on a line alone and will be formed by legal characters (as defined above ). all travel sequences will appear in a single line and will have at most 100 cities.

The Output

For each sequence pair, you must print the following message in a line alone:

Case # d: you can visit at most K cities.
Where d stands for the test case number (starting from 1) and K is the maximum number of cities you can visit such that you'll satisfy both you father's suggestion and you mother's suggestion.

Sample Input

Abcdacdbabcddacb #

Sample Output

Case #1: you can visit at most 3 cities. Case #2: you can visit at most 2 cities. Please wait

Uva10192-Vacation

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.