UVa 10238 - Throw the Dice Solution

a=[]
f=0
def rec(t,s):
    if t<0 or s<0 or 1*t>s or f*t<s:
        return 0
    if t==0 and s==0:
        return 1
    global a
    if a[t][s] is not None:
        return a[t][s]
    tmp=0
    for i in range(1,f+1):
        tmp+=rec(t-1,s-i)
    a[t][s]=tmp
    return tmp
def Main():
    try:
        while True:
            ff,t,s=input().split()
            ff=int(ff)
            t=int(t)
            s=int(s)
            global f
            f=ff
            global a
            a=[[None for x in range(s+1)] for x in range(t+1)]
            print("%d/%d"%(rec(t,s),f**t))
    except EOFError:
        return 0
if __name__=='__main__':
    Main()

Comments