> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0276_paint_fence/slt.md).

# 思路1 dp

第一个栏杆有k种办法： 第二个栏杆有k\*k种办法

超过3根栏杆动态规划才有意义： 如果超过3根栏杆,才有可能出现, 1.第三根栏杆刷第二根栏杆颜色(这时候就需要考虑第二根栏杆是不是和第一根栏杆一样颜色, 所以也是k-1) : dp\[i] = dp\[i-2]*(k-1) 2.第三根栏杆不刷第二根栏杆颜色 ：dp\[i] = dp\[i-1]*(k-1)
