超弦InterviewStreet:Python的 [英] Hyper Strings InterviewStreet: Python

查看:127
本文介绍了超弦InterviewStreet:Python的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://www.interviewstreet.com/challenges/dashboard/#problem/ 4f802ebfad2a1
我的code是通过6/10的测试用例。

https://www.interviewstreet.com/challenges/dashboard/#problem/4f802ebfad2a1
My Code is passing 6/10 test cases.

from collections import Counter
j,k = map(int, raw_input().split())

y = Counter(len(raw_input()) for i in range(j))

saved = {}

def f(x):
    if x in saved:  return saved[x]
    if x<1: return 0
    k = y[x] if x in y else 0
    for i in y:
        k += y[i]*f(x-i)
   saved[x] = k
   return k
x = 0
for i in xrange(1,k+1):
    x+=f(i)

print (x+1)%1000000007

键入Y是超弦的长度,它的价值是超弦与设置'H'的长一些。

Key in 'y' is length of super string and its Value is number of super strings with that length in set 'H'.

保存记忆化处理。

F(X)计算的长度x的超字符串。我经历了去年的所有值循环的循环。

f(x) calculates hyper strings of length x. I iterate through all values in last 'for loop'.

x具有导致除空字符串(''),因此,X + 1

x has result except empty string (''), therefore x+1

推荐答案

我觉得这$​​ C $ C失败的情况下,当任何超串是任何其他超级字符串Concat的。 在这种情况下,该code会增加某些情况下多次。 例如:

I think this code fails in the cases when any super string is concat of any other super strings. In this case, this code will add some cases multiple times. Eg:

3 2
a
b
ab

您输出:8
右输出:7
的AB
重复计算 我是我自己想的问题,将发布答案的情况下,分数10/10

Your Output : 8
Right Output : 7
Double Counting of "ab"
I am myself trying the question, will post the answer in case it scores 10/10

这篇关于超弦InterviewStreet:Python的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆