Solution:
Define dp[i] to represent the answer when n=i. We use the case n=4 to explain the solution.
Firstly, consider 2 special cases. As images below:
![](https://zh.xloypaypa.pub/content/images/2021/05/image-13.png)
![](https://zh.xloypaypa.pub/content/images/2021/05/image-14.png)
In case warp a segment for all, so we know dp[n]=2+dp[n-1]+?.
![](https://zh.xloypaypa.pub/content/images/2021/05/image-10.png)
Then, in case wrap two segments for all, dp[n]=2+dp[n-1]+dp[n-2]+?.
![](https://zh.xloypaypa.pub/content/images/2021/05/image-11.png)
And so on, we know that $dp[n]=2+\sum_{i=1}^{n-1}{dp[i]}+?$.
Now, still one case left: we can split n=4 to two n=2 and make all the length of segment is the same. So, for each factor of n, it is a new answer.
![](https://zh.xloypaypa.pub/content/images/2021/05/image-12.png)
So, $dp[n]=2+\sum_{i=1}^{n-1}{dp[i]}+count\_of\_factor[n]$.
Code:
Java
Submission #117253890 - Codeforces
Codeforces. Programming competitions and contests, programming community
![](https://codeforces.org/s/15761/images/codeforces-telegram-square.png)
C++
Submission #117257391 - Codeforces
Codeforces. Programming competitions and contests, programming community
![](https://codeforces.org/s/15761/images/codeforces-telegram-square.png)