K-important StringsProblem code: N3 |
All submissions for this problem are available.
You are given a set of N strings S0, S1, …, SN-1. These strings consist of only lower case characters a..z and have the same length L.
A string H is said to be K-important if there are at least K strings in the given set of N strings appearing at K different positions in H. These K strings need not to be distinct.
Your task is to find the shortest K-important string. If there are more than one possible solution, your program can output any of them.
Input
The first line contains a number t (about 10) which is the number of test cases.
Each test case has the following form.
The first line contains three integers N, L and K. The next N lines contain the strings in the given set.
Each test case's input is separated by a blank line.
Constraints
- 1 ≤ N ≤ 150
- 1 ≤ L ≤ 300
- 1 ≤ K ≤ 500
Output
For each test case, output the following information.
The first line contains the length of the shortest K-important strings.
The second line contains H, one of the K-important strings.
Each line in the next K lines contains the index of one string in the given set that appears in H and the corresponding position (0-based) in H.
Print a blank line after each test case's output.
Example
Input 3 3 3 1 abc cde bcf 3 3 2 abc cde bcf 3 3 3 abc cde bcf Output 3 abc 0 0 4 abcf 0 0 2 1 7 abcfabc 0 0 2 1 0 4
Comments

Fetching successful submissions

Isn,t the output of 3rd test
Isn,t the output of 3rd test case is given wrong?
@Mahesh The test cases look
@Mahesh The test cases look correct to me.
hi frnds i'm new in ths
hi frnds i'm new in ths competition...r we going to check the input given by the user is correct or not? or we hv to keep in mind tht the input supplied by the user will always be correct i.e. in above problem instead of chars a-z if user enters digits wt shd be done? pls clarify for all the problems. Thnks.
@janak If you're new, you
@janak If you're new, you should probably read all of the FAQ. The input is guaranteed to be correct.
Are the given n strings
Are the given n strings distinct??
Please read the problem
Please read the problem statement again.
can anybody explain the
can anybody explain the problem...plssss
@Ankush By definition, a set
@Ankush By definition, a set of N items contains N distinct items.
@AMRITPAL A string H is
@AMRITPAL A string H is K-important if, and only if, we can find at least K different positions i in H satisfying the criterion below. The criterion is that the substring of H consisting of the characters i to [i + (L − 1)] matches one of the strings in {S0, …, SN − 1}.
@brain pls elloborate with an
@brain
pls elloborate with an example. i didn't get it. pls...
thanx for your response...
explain the H and L term in your comment...
my submission is showing
my submission is showing runtime error(other)...
what can be the probable reasons???
got the error, K and N were
got the error, K and N were swapped in one of the declared variable (segmentation fault),now accepted :)
I changed the input of the
I changed the input of the string from
for(int i=1; i<=N; i++) {
for(int j=1; j<=L; j++) do scanf("%c", &s[i][j]) while(s[i][j]==' ' || s[i][j]=='n');
}
to
for(int i=1; i<=N; i++) scanf("%s", &(ss[i][1]));
and got AC from WA.
Does that mean, the input does not follow the specifications in the problem statement?
This WA had been bugging me for a LONG time !
No, the first code you wrote
No, the first code you wrote is wrong. You probably haven't read the FAQ.
Can anybody explain that what
Can anybody explain that what will be the output if input is
Input
4
4 4 1
abcd
bcde
cdef
defg
4 4 2
abcd
bcde
cdef
defg
4 4 3
abcd
bcde
cdef
defg
4 4 4
abcd
bcde
cdef
defg
hey admin...i am bit
hey admin...i am bit confused abt output...
Each line in the next K lines contains the index of one string in the given set that appears in H and the corresponding position (0-based) in H.
as in input is
@Ashish it means 0th string
@Ashish
it means 0th string starts from 0th index of "abc"
I had a overview of the FAQ
I had a overview of the FAQ but could not get the soln.
Please do explain...
I got the solution accepted
I got the solution accepted by changing gets to scanf("%s"). I think there is something wrong with the input format. It won't matter for people who use scanf, but the input format should be exactly as mentioned in the question.
Nothing is wrong with the
Nothing is wrong with the input format.
@charango, I think the
@charango, I think the output would be
During a running contest,
During a running contest, discussing input values beyond those given can (and should) result in disqualification. Contestants are supposed to work out any extraneous inputs themselves, without any help. Discussing them in public is unfair to those who have already made submissions. It is not hard to fathom that a good part of the challenge in such contests lies in coming up with your own test cases without anyone else being privy to them. Discussing them in public ruins it for everyone.
@ADMINS - This is a serious concern and compromises the integrity of these competitions. I hope you take care of such episodes.
@admin: Is the contest over.
@admin: Is the contest over. I am not able to submit solution for this contest any more. Kindly help.
how DP is to be used in this
how DP is to be used in this problem???