Dynamic Programming Paint Fence Algorithm
Dynamic Programming Paint Fence Algorithm
Dynamic Programming Paint Fence Algorithm
(ISAS)
Arranged by:
Faculty :
Information Technology
2018
PREFACE
Thank you, the writer wishes to God the Almighty for His blessings and
blessings, we can complete this ISAS task both in the form of presentation and
paper in a timely manner.
Not forgetting the thanks especially for Listyo faculty and other faculty who
always help. Thank you also to fellow students who have supported, and also thank
you for being fellow workers in the education at CCIT-FTUI. The ISAS paper
entitled ' Dynamic Programming Paint Fence Algorithm’ the author submits as a
requirement for the ISAS assignment in 2019.
Hope the author, hopefully this paper can be useful for all so that it can add
knowledge and insight. The author realizes that this paper is far from perfect.
Therefore, the authors really expect all suggestions and criticisms from readers who
are constructive in order for the perfection of this paper. Finally, hopefully this
paper can provide many benefits for the readers.
Author
i
TABLE OF CONTENT
Contents
PREFACE ................................................................................................................ i
TABLE OF CONTENT .......................................................................................... ii
CHAPTER I INTRODUCTION ............................................................................. 1
Background ......................................................................................................... 1
Writing Objectives .............................................................................................. 2
Problem Domain ................................................................................................. 2
Writing Methodology .......................................................................................... 2
Writing Framework ............................................................................................. 2
CHAPTER II BASIC THEORY ............................................................................. 4
Algorithm ............................................................................................................ 4
Data Structure...................................................................................................... 4
Dynamic Programming ....................................................................................... 5
Dynamic Programming Paint Fence Algorithm .................................................. 5
CHAPTER III ......................................................................................................... 6
PROBLEM ANALYSIS ......................................................................................... 6
III.1 Paint Fence Algorithm ................................................................................ 6
III.2 Code ............................................................................................................ 7
CHAPTER IV ....................................................................................................... 10
CONCLUSION AND SUGGESTION ................................................................. 10
IV.1 Conclusion ................................................................................................ 10
IV.2 Suggestion ................................................................................................. 10
BIBLIOGRAPHY ................................................................................................. 11
ii
CHAPTER I
INTRODUCTION
Background
1
2
Writing Objectives
1. What is algorithm?
2. What is Dynamic Programing?
3. What is Paint Fence Algorithm
Problem Domain
Writing Methodology
Writing Framework
CHAPTER I : INTRODUCTION
This chapter deals with problem analysis such as the definition of shell sort,
how shell sort works and the advantages also disadvantages.
BIBLIOGRAPHY
Algorithm
Data Structure
4
5
Dynamic Programming
There is a fence algorithm with posts, each post can be painted with one of the
colors. The user have to paint all the posts such that no more than two adjacent
fence posts have the same color. Return the total number of ways the user can paint
the fence algorithm. diff number of combinations with different colors.
Paint Fence is one of the basic Dynamic Programming problems. It can be
solve in many ways, and have a variety solution. With this we can learn more about
dynamic programming solving, and we can implement it to any code to make it
more efficient.
CHAPTER III
PROBLEM ANALYSIS
N=1
there is only k possibilities there for total = k
N=2
For the same color eac post there is k possibility, so same = k
For the different color we have k*(k-1), so diff =k*(k-1)
And total = k+(k*(k-1))
N=3
For the same we have, same = k*(k-1)
For different color, diff = (k+(k*(k-1)))*(k-1)
And total = (k*(k-1)) + (k+(k*(k-1)))*(k-1)
same[i] = diff[i-1]
and that we have the counting in mathe matical way. Notice that we can sorten the
algorithm with arrays. This is a coomon dynamic programing problems that
requires to solve it into little sub problems
6
7
III.2 Code
We can also put an array to replace the one variable that way we can store the sub
problem by adding 1 more to the array
8
dp[1]=k;
int same = 0;
int diff = k;
same = diff;
return dp[n];
int n =3;
int k =4;
System.out.println(Count(n,k));
}
9
Is quite simple and effective way to sole a dynamic programming problem, and
that is to break it into subproblem and solve it .
CHAPTER IV
IV.1 Conclusion
IV.2 Suggestion
We suggest for the readers that read this is to apply dynamic programming in
their code for more efficient way to solve problems in much faster time consume.
10
BIBLIOGRAPHY
Alif, M. (2015, November 11). Jenis jenis sorting. Retrieved from Techno X Info
X Def: http://web.if.unila.ac.id/muhammadalif/2015/11/12/jenis-jenis-sorting/
11