Translate

Views

Sunday, August 25, 2024

Solution Uva: 10338 - Mischievous Children

 

 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10338 - Mischievous Children AcceptedPython1.0200.00044645 mins ago

Suggest:

1/ RESULT = ALL CASE  - SAME CASE

2/ ALL CASE  = n! (n is length string)

3/ SAME CASE = a! * b! * ... * c! (with a,b,c is number of same chars ) 


from functools import cache

@cache
def fac(n):
    if n == 1:
        return 1
    return fac(n - 1) * n


n = int(input())
for i in range(1, n+1):
    s = input()
   
    d = {}
    for c in s:
        if c not in d:
            d[c] = 1
        else:
            d[c] += 1

    r = fac(len(s))
    for key in d:
        r //= fac(d[key])
    print(f'Data set {i}: {r}')

No comments: