------
## 最终结论
```python
def count_no_of_ways(n, k):
    if n == 0:
        return 0
    if n == 1:
        return k
    if n == 2:
        return k * k

    # dp[i] will hold the number of ways to paint i posts
    dp = [0] * (n + 1)
    
    # Base cases
    dp[1] = k
    dp[2] = k * k
    
    for i in range(3, n + 1):
        dp[i] = (k - 1) * (dp[i - 1] + dp[i - 2])
    
    return dp[n]
```