DP [light OJ 1013] Love Calculator

Source: Internet
Author: User

1013-love Calculator

Yes, you're developing a ' Love Calculator '. The software would is quite complex such that nobody could crack the exact behavior of the software.

So, given names your software would generate the percentage of their ' love ' according to their names. The software requires the following things:

    1. The length of the shortest string that contains the names as subsequence.
    2. Total number of unique shortest strings which contain the names as subsequence.

Now your task was to find these parts.

Input

Input starts with an integer T (≤125), denoting the number of test cases.

Each of the test cases consists of, lines each containing a name. The names would contain no more than -capital letters.

Output

For each of the test cases, you need to print one line of output. The output for each test case starts with the test case number, followed by the shortest length of the string and the numb Er of unique strings that satisfies the given conditions.

You can assume that the number of the unique strings would always is less than 263. Look at the sample output for the exact format.

Sample Input Output for Sample Input

3

USA

USSR

Laili

Majnu

Shahjahan

Momtaj

Case 1:5 3

Case 2:9 40

Case 3:13 15

Did this problem, only tears left.

The first memory of the search, do not build where the wrong WA.

Then DP, and then wrote L2 12, just like the example again, Wa, a variety of tests, but also thought the compiler problem

And then, since the beginning of the array opened up, super memory, and then small, and then do not create how, the array of a smaller output a string of inexplicable numbers, AC only to find it seems to be Midway array Subscript 1 of the reason for cross-border.

Then change it, because the initialization is wrong, after all the data in the discussion, WA in the first group, Output 6 2.

Last change, Ac.

Can't stand,--

I'm two!

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;#defineINF 0x7fffffff#definell Long Longll L1,l2;Chars1[ -];Chars2[ -];ll dp[ -][ -][ the];//Dp[i][j][k] Indicates the number of schemes that contain the first I characters in the 1th string and the first J characters in the 2nd string when the length is K. intMain () {ll i,j,k,t,icase=1; scanf ("%lld",&T);  while(t--) {memset (DP,0,sizeof(DP)); scanf ("%s%s", s1+1, s2+1); L1=strlen (s1+1); L2=strlen (s2+1);  for(i=0; i<=l1;i++) dp[i][0][i]=1;  for(j=0; j<=l2;j++) dp[0][j][j]=1;//Note the initialization details         for(k=1; k<=l1+l2;k++)        {             for(i=1; i<=l1;i++)            {                 for(j=1; j<=l2;j++)                {                    if(s1[i]==S2[j]) {Dp[i][j][k]+=dp[i-1][j-1][k-1]; }                    Else{Dp[i][j][k]+=dp[i-1][j][k-1]+dp[i][j-1][k-1]; }                }            }        }         for(k=1; k<=l1+l2;k++)        {            if(Dp[l1][l2][k]) { Break; }} printf ("Case %lld:%lld%lld\n", icase++, K,dp[l1][l2][k]); }    return 0;}

DP [light OJ 1013] Love Calculator

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.