首页 > ACM题库 > HDU-杭电 > HDU 2882-The k-th String sequence-待解决[解题报告]
2014
02-17

HDU 2882-The k-th String sequence-待解决[解题报告]

The k-th String sequence

问题描述 :

Given a String s, we will first collect all distinct positive length subsequences of s, and place them in a list L. A subsequence of s is obtained by deleting 0 or more characters. Next, sort L into ascending order by length. Where ties occur, break them lexicographically. Here uppercase letters occur before lowercase letters. Finally, return the String in position k % TOTAL (0-based), where TOTAL is the number of elements in L.

输入:

Line 1: The input contains a single integer T , the number of test cases.Line 2…T+1: s k (The input string s and the position of the output string).(The length of s is between 2 and 50. Each character in s will be a letter (‘A’-'Z’,'a’-'z’).
k will be an integral value between 0 and 2^63 – 1 inclusive. )e.

输出:

Line 1: The input contains a single integer T , the number of test cases.Line 2…T+1: s k (The input string s and the position of the output string).(The length of s is between 2 and 50. Each character in s will be a letter (‘A’-'Z’,'a’-'z’).
k will be an integral value between 0 and 2^63 – 1 inclusive. )e.

样例输入:

3
ABCD 15
ABCD 14
AbcdAbcdAbcd 39283423984923

样例输出:

A
ABCD
AbAbdbd

有趣的数学递推题

长度小于50的只含有大小写字母的字符串,再给一个数k,这个字符串的字序列(注意不是string,而是sequence)设有m种,按照字典序排列 (如有相同的按1种算,如AAA只有3个子序列:A,AA,AAA),求第k%m+1个sub-sequence,并输出。

可用动态规划求解。


  1. “再把所有不和该节点相邻的节点着相同的颜色”,程序中没有进行不和该节点相邻的其他节点是否相邻进行判断。再说求出来的也不一样是颜色数最少的