twoPostsBack and onePostBack, to represent the number of ways to paint the fence with one and two posts, respectively.twoPostsBack = k and onePostBack = k * k to represent the base cases.n-th post.curr = (k - 1) * (onePostBack + twoPostsBack).twoPostsBack to the value of onePostBack, and onePostBack to the value of curr.onePostBack as the final answer.