Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:58:38+00:00 2026-06-13T19:58:38+00:00

my code is like this which work too long for rows and cols >

  • 0

my code is like this which work too long for rows and cols > 15, is there any better solutions ?
Problem link: https://projecteuler.net/problem=15

#!/usr/bin/env python
rows = 3
cols = 3
start_row = 0
start_col = 0
count = 0

def trace(row, col):
    if row == rows and col == cols:
        global count
        count += 1
        return 
    if col + 1 <= cols:
        # print row, col
        trace(row, col + 1)

    if row + 1 <= rows:
        # print row, col
        trace(row + 1, col)

trace(start_row, start_col)
print count
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:58:40+00:00Added an answer on June 13, 2026 at 7:58 pm

    finally I got it, using dynamic programing could solve the problem.

    #!/usr/bin/env python
    rows = 20
    cols = 20
    pre_list = {}
    
    count = 0
    pre_list = {}
    for i in xrange(0, rows + 1):
        for j in xrange(0, rows + 1):
            pre_list[(i,j)] = []
    
    for i in xrange(0, rows + 1):
        for j in xrange(0, rows + 1):
            if i > 0:
                pre_list[(i,j)].append((i-1, j))
            if j > 0:
                pre_list[(i,j)].append((i, j-1))
    
    route = {(rows,cols):1}
    
    keys = route.keys()
    while True:
        if not keys:
            break
    
        new_route = {}
        for key in keys:
            # print 'key', key
            pre = pre_list[key]
            if not pre:
                continue
            for item in pre:
                new_route[item] = 1
                # print 'route', route
                if item in route:
                    route[item] += route[key]
                else:
                    route[item] = route[key]
                # print 'route', route
            route[key] = 0
            # print new_route
        keys = new_route.keys()
        # print 'new keys', keys
    
    print route[(0,0)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code like this below, which gives me a $link that equals
I have code which needs to do something like this There is a list
I have a code like this, which is solved by me following a exercise
I am reading a book in which author used a code like this public
i have a code which is like this : private void testToolStripMenuItem_Click(object sender, EventArgs
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have some Java code which looks roughly like this: String urlString = ftp://polar.ncep.noaa.gov/pub/history/waves/multi_1.glo_30m.dp.200601.grb2;
I'm training code problems like UvA and I have this one in which I
I have lot of code in my Tornado app which looks like this: @tornado.web.asynchronous

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.