Hduoj 2050-polyline split plane (recursive solution)

Source: Internet
Author: User
Tags polyline
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]);
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.