Very good a problem, think of the way to feel very amazing.
Test instructions
The number on the axis has \ (d\) A continuous integer scale, there are \ (n\) tree to be planted on these scales, where the first \ (i\) tree and on both sides (if any) adjacent to the tree at least (r_i\), ask methods.
\ (1 \leq N, R_i \leq 40\)
Ideas:
First, if the order of the trees is determined, the minimum spacing of the adjacent trees is determined. Subtract the sum of the minimum spacing from \ (d\) , resulting in the number of "redundant ticks".
This number is allocated to the (n+1\) segment clearance, the method number can be obtained by inserting the plate method.
So the problem is, for each \ (l\), find the number of permutations \ (p\) of 1 to \ (n\ ), satisfying:
\[\sum_{i=1}^{n-1} \mathrm{max} (R_i, r_{i+1}) =l\]
Note that for the maximum \ ( r_i\) \ (i\), what tree is planted on either side of it, it does not affect the minimum length of the two gaps.
According to the routine, this time we should be in the position of \ (i\) cut open and processed separately.
For a 1 to \ (n\) subset of the length of \ (l\) for the arrangement \ (p\), the cost of the definition is:\ (\sum_{i=1}^{l-1} \mathrm{max} (R_i, r_{i+ 1}).
So think of the DP state:\ (dp[i][j][k]\) , 1 to \ (i\) this \ (i\) number, composed of \ (j\) a disjoint arrangement, the cost sum of the arrangement is \ (k\) number of methods.
When transferring, consider whether the number of I\ is at the end or the middle of an arrangement, and delete it and transfer it.
Notice \ (i,j \leq 40\),\ (k \leq 1600\), so the complexity is fine.
SRM489 Div1 1000pts:appletree