Difficult Melody (ing), difficultmelody

Source: Internet
Author: User

Difficult Melody (ing), difficultmelody

Question Link

Http://vjudge.net/contest/137242#problem/D

 

Description

You're addicted to a little game called 'Remember the melody ': you hear some notes, and then you repeat it. in most cases, the longer the melody, the harder to repeat, but it isn' t always true. also, melodies of the same length are usually not equally easy to remember. to find a way to define the remember difficulty of a melody, you Have Ted a statistics-based model:



Suppose you're ststigating melodies of a participant length. if a melody appeared in p games, among which you successfully repeated q games, the smaller q/p, the more difficult the melody. if there is more than one melody having the minimal ratio, the one with larger p is considered more difficult. but there is an exception: if p is smaller than a threshold m, you simply ignore it (you can't cal L it difficult if you haven't tried it a lot of times, can you ?). The melody appears in a game if its string representation is a consecutive substring occurring at least once in that game.

Write a program to find the most difficult melody of length k, given n games you 've played.

Input

The input contains several test cases. each case consists of three integers n, m, k (1 <= m <= n <= 100, 1 <= k <= 20 ), the next n lines each contain two strings separated by exactly one space: the game, and whether you successfully repeated it. the first string will contain at least one at most 100 upper case letters 'C', 'D', 'E', 'F', 'G', 'A ', 'B '. the second string will be either 'yes' or 'no' (case sensitive ). the last test case is followed by a single zero, which shoshould not be processed.

Output

For each test case, print the case number and the most difficult melody. if there is more than one solution, output the lexicographically smallest one. if there is no solution, output the string 'no solution '.

Sample Input

3 2 3 EEECEG Yes BFCEG No DEBFCEGEEC No 3 2 2 AAA No BBB No CCC Yes 0

Sample Output

Case 1: BFC Case 2: No solution


Enter n, m, and k in the next n rows. Enter 1 ~ for each row ~ String of 100 (only uppercase letters 'C', 'D', 'E', 'F', 'G', 'A', 'B '), enter "Yes" or "No" to find the most difficult string with a length of k. The most difficult string is defined as follows: set this substring to appear p times in n strings, q appears in a string that is "Yes". If the q/p ratio is smaller than the q/p ratio, make sure that p> = m otherwise this string is not taken into account. If the ratios of multiple strings are the same, the payment string with a large p value is output. If multiple p values are the same, output A string with a small Lexicographic Order;

Idea: Use two sets to record the number of times that these k-length substrings appear in n strings and the number of times that they appear in the string "Yes;

The Code is as follows:
#include <iostream>#include <algorithm>#include <stdio.h>#include <cstring>#include <cmath>#include <map>#include <bitset>using namespace std;typedef long long LL;map<string,int>mp1;map<string,int>mp2;///Yes;map<string,int>mp3;map<string,int>::iterator it;int main(){    int n,m,k,Case=1;    while(scanf("%d",&n)&&n)    {        scanf("%d%d",&m,&k);        mp1.clear();        mp2.clear();        char s1[105],s2[10];        for(int j=0; j<n; j++)        {            scanf("%s%s",s1,s2);            int len=strlen(s1);            mp3.clear();            for(int i=len-k; i>=0; i--)            {                s1[i+k]='\0';                string s=(string)(s1+i);                if(mp3[s]==0){                    mp3[s]++;                    mp1[s]++;                    if(s2[0]=='Y') mp2[s]++;                }            }        }        int t1=9999,t2=99;        string str="";        for(it=mp1.begin(); it!=mp1.end(); it++)        {            if(it->second>=m)            {                int w1=mp2[it->first];                int w2=it->second;                int f=w1*t2-w2*t1;                if(f<0||f==0&&w2>t2||f==0&&w2==t2&&(str>(it->first)))                {                    str="";                    str+=it->first;                    t1=w1;                    t2=w2;                }            }        }        printf("Case %d: ",Case++);        if(t1==9999&&t2==99) puts("No solution");        else cout<<str<<endl;    }    return 0;}
 

Related Article

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.