Articles
Windows FAQ
"Microsoft Silverlight" Installed Program on Windows 7 - What is...
"Microsoft Visual C++ 2005 Redistributable" Installed Program on...
"Microsoft Visual C++ 2005 Redistributable (x64)" Installed Prog...
"Microsoft Visual C++ 2008 Redistributable - x64 9.0.21022" Inst...
"Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17" I...
Who's Online
4 user(s) are online (1 user(s) are browsing Forum)

Members: 0
Guests: 4

more...

Browsing this Thread:   1 Anonymous Users





Algorithms for coding interviews - dynamic programming
Home away from home
Joined:
2007/11/11 12:07
Group:
Registered Users
Posts: 328
Level : 16; EXP : 92
HP : 0 / 398
MP : 109 / 10991
Offline
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 ] ;
else
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: 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) 2015 FYIcenter.com
Search
Main Menu
Login
Username:

Password:

Remember me



Lost Password?

Register now!