description
There are n straight lines on the plane, three lines and no common points, straight lines can be asked how many different intersection points.
For example, if n = 2, the number of possible intersection point is 0 (parallel) or 1 (non-parallel).
Entry
Input data comprising a plurality of test cases, each test case per line, each line contains a positive integer n (n <= 20), n represents the number of straight lines.
Export
Each test case corresponds to one line of output, from small to large to list all intersect scheme wherein each possible number of cross-points, an integer between each row separated by a space.
Sample input
2
3
Sample Output
0 1
0 2 3
Source title
HDOJ
Analysis:
dynamic programming, there are provided n straight lines m parallel lines,
the intersection of straight lines n = m * of parallel lines (nm) + intersection of straight lines (nm) straight lines.
Code:
#include <bits / STDC ++ H.>
The using namespace STD;
int main ()
{
int A [21 is] [201], n-;
Memset (A, 0, the sizeof (A));
A [0] [0] = A [. 1] [0] =. 1;
for (int I = 2; I <21 is; I ++)
{
A [I] [0] =. 1;
for (int J =. 1; J <I; J ++)
{
int X = J;
int Y = ij of;
for (int K = 0; K <= Y * (Y-. 1) / 2; K ++) // C (n-, 2) / 2
{
IF (A [Y] [K ])
A [I] [X Y + K] =. 1;
}
}
}
the while (n->> CIN)
{
int T = 0;
for (int I = 0; I <= n- (n--. 1) / 2; ++ I)
{
if (i==0) {cout<<i;T=1;}
else
if (a[n][i])
{
if (T) cout<<’ ';
cout<<i;
}
}
cout<<endl;
}
return 0;
}