Original question :
Problem Description
We've seen a lot of straight-line split-plane problems, and this topic is slightly different today, and we're asking for the maximum number of n-polyline split planes. For example, a polyline can divide the plane into two parts, and a maximum of two polylines can be divided into 7 parts, as shown below.
Input
The first line of the input data is an integer c, representing the number of test instances, followed by the C row of data, each line containing an integer n (0 < n<=10000) representing the number of polylines.
Output
For each test instance, output the maximum number of partitions for the plane, and the output for each instance takes up one row.
Sample Input
2
1
2 Sample Output
2
7 thinking: F (n) =f (n-1) +4 (n-1) +1 You can understand this:
When n=2, there are two lines when you want to draw a polyline, you can split the most plane of the case is that the two lines of the polyline is the same as the previous 2 existing lines are now intersecting, that is, the third polyline is divided into 5 segments of the two line respectively (You can try to draw it out to see it) and then the 10 paragraphs have 8 of the space divided into 2 parts of the remaining two pieces are connected together (that is, the corner of the polyline), calculated to split out a part so F (3) =f (2) +4* (3-1) +1=7+8+ 1=15 Code: Recursive solver – finding recursive formulas
#include <stdio.h>
int dp[10001] = {0,2};
int main ()
{
int C, n, I;
for (i = 2; I <= 10001; i++)
dp[i] = dp[i-1] + (i-1) * 4 + 1;
scanf ("%d", &c);
while (c--)
{
scanf ("%d", &n);
printf ("%d\n", Dp[n]);
}
}