Note that there are some explanatory texts on larger screens.

plurals
  1. POTopCoder algorithm problem - how to make progress on this one?
    primarykey
    data
    text
    <p>I've recently joined TopCoder and have been practicing in the Practice Rooms for the last few days. I came across this problem which I cant seem to solve. Any help will be appreciated. </p> <p><strong>The problem</strong></p> <blockquote> <p>The product value of a string is the product of all the digits ('0'-'9') in the string. For example, the product value of "123" is 1 * 2 * 3 = 6. A string is called colorful if it contains only digits and the product value of each of its nonempty contiguous substrings is distinct. </p> <p>For example, the string "263" has six substrings: "2", "6", "3", "26", "63" and "263". The product values of these substrings are: 2, 6, 3, 2 * 6 = 12, 6 * 3 = 18 and 2 * 6 * 3 = 36, respectively. Since all six product values are distinct, "263" is colorful. </p> <p>On the other hand, "236" is not colorful because two of its substrings, "6" and "23", have the same product value (6 = 2 * 3). </p> <p>Return the k-th (1-based) lexicographically smallest colorful string of length n. If there are less than k colorful strings of length n, return an empty string instead.</p> </blockquote> <p><strong>My approach</strong></p> <p>We can't have '0' and '1' as digits in n. All digits must be distinct. So to begin with, n should be smaller than 9. (only the digits 2, 3, 4, 5, 6, 7, 8, 9 can be used, each of them only once).</p> <p>Since we know that, we can start with "23" (the smallest 2-digit colorful string) as the base string and add one of the allowed digits (check if the string is still colorful or not, on each addition) until we reach length n.</p> <p>Once we reach length n, we can "play around" with the digits to find the k-smallest.</p> <p><strong>My question</strong></p> <p>I feel like this approach will not be fast enough. Even if it is, in what systematic way should I play around with the digits, so that I start from the smallest and make my way through the kth-smallest?</p> <p>How can I make progress on this problem with this approach? Or are there smarter ways to follow in these kind of problems?</p> <p>I'm not asking for any solutions or anything. I'm just asking for some clues and some lead.</p> <p>Some problems I solve in seconds, some take hours of thinking and some like this I can't do it. But I believe all it takes is some practice, but I cannot make progress without someone leading the way.</p> <p>Thanks in advance =)</p> <p>*by the way, this question is from SRM 464 DIV 2 - 500pt. problem. All copyright goes to TopCoder.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload