Reprint please indicate the source: http://blog.csdn.net/u012860063? Viewmode = Contents
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1466
Calculate the intersection points of a straight line. The problem description plane has n straight lines without the Three-line common points. Ask how many different kinds of intersection points can be obtained for these straight lines.
For example, if n = 2, the number of possible intersections is 0 (parallel) or 1 (non-parallel ). The input data contains multiple test instances. Each test instance occupies one row. Each row contains a positive integer n (n <= 20). N indicates the number of straight lines.
Output: each test instance corresponds to a single line of output, and all the intersection schemes are listed from small to large. Each number of possible intersection points is separated by a space.
Sample Input
23
Sample output
0 10 2 3
The Code is as follows:
# Include <cstring> # include <iostream> using namespace STD; # define N 21 # define M (N-1) * n/2int DP [N] [m]; // DP [I] [J] I is a line where J represents the number of intersections void solve () {int m = 0; memset (DP, 0, sizeof (DP); DP [0] [0] = 1, DP [1] [0] = 1; for (INT I = 2; I <= 20; I ++) {for (int K = 0; k <I; k ++) {for (Int J = 0; j <= K * (k-1)/2; j ++) {If (DP [k] [J]) {M = J + K * (I-k); DP [I] [m] = 1; // tag }}} int main () {int N; solve (); While (~ Scanf ("% d", & N) {printf ("0"); For (INT I = 1; I <= N * (n-1)/2; I ++) {If (DP [N] [I]) {printf ("% d", I) ;}} printf ("\ n ");} return 0 ;}