Project Euler #15: Lattice paths

  • + 0 comments

    passed all test cases

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import sys
    
    sys.setrecursionlimit(5000)
    
    def findpath(n , m, seen):
        if (n,m) in seen:
            return(seen[(n,m)]%(7+10**9))
        if n == 0 or m == 0:
            return(1)
        else:
            seen[(n,m)] = (findpath(n-1,m,seen)+findpath(n,m-1,seen))%(7+10**9)
            return(seen[(n,m)])
            
    seen = {(0,0): 1}
    
    findpath(500, 500, seen)
    
    for a0 in range(int(input())):
        n, m =list(map(int, input().split()))
        print(seen[(n, m)])
    

    for a0 in range(int(input())): n, m =list(map(int, input().split())) print(seen[(n, m)])****