Main Menu


Remember me

Lost Password?

Register now!
Who's Online
19 user(s) are online (12 user(s) are browsing Forum)

Members: 0
Guests: 19


Browsing this Thread:   1 Anonymous Users

Algorithms for coding interviews - dynamic programming
Home away from home
2007/11/11 12:07
Registered Users
Posts: 329
Level : 16; EXP : 94
HP : 0 / 398
MP : 109 / 12169
Algorithms for coding interviews - dynamic programming

Dynamic programming is a technique for solving problems with the following properties:

 An instance is solved using the solutions for smaller instances.
 The solution for a smaller instance might be needed multiple times.
 The solutions to smaller instances are stored in a table, so that each smaller instance is solved
only once.
 Additional space is used to save time.
The problem of climbing steps perfectly fit those 4 properties. Therefore, it can be solve by using
dynamic programming.
public s t a t i c int [ ] A = new int [ 1 0 0 ] ;
public s t a t i c int f3 ( int n) {
i f (n <= 2)
A[n]= n ;
i f (A[n] > 0)
return A[n ] ;
A[n] = f3 (n􀀀1) + f3 (n􀀀2) ; / / s t o r e r e s u l t s s o only c a l c u l a t e onc e !
return A[n ] ;

Posted on: 2017/4/3 15:49
Transfer the post to other applications Transfer

You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.

[Advanced Search]

Copyright (c)