先决条件:排列组合
给定一个 m 边的多边形,计算可以使用多边形的顶点形成的三角形的数量。
Answer : [m (m – 1)(m – 2) / 6]
Explanation : There are m vertices in a polygon with m sides. We need to count different combinations of three points chosen from m. So answer is mC3 = m * (m – 1) * (m – 2) / 6
Examples :
Input: m = 3
Output: 1
We put value of m = 3, we get required no. of triangles = 3 * 2 * 1 / 6 = 1
Input : m = 6
output : 20
给定一个 m 边的多边形,计算可以使用多边形的顶点形成的对角线数。
Answer : [m (m – 3)] / 2.
Explanation : We need to choose two vertices from polygon. We can choose first vertex m ways. We can choose second vertex in m-3 ways (Note that we can not choose adjacent two vertices to form a diagonal). So total number is m * (m – 3). This is twice the total number of combinations as we consider an diagonal edge u-v twice (u-v and v-u)
Examples:
Input m = 4
output: 2
We put the value of m = 4, we get the number of required diagonals = 4 * (4 – 3) / 2 = 2
Input: m = 5
Output: 5
计算使用 m 条垂直线和 n 条水平线可以形成的矩形总数
Answer : (mC2*nC2).
We need to choose two vertical lines and two horizontal lines. Since the vertical and horizontal lines are chosen independently, we multiply the result.
Examples:
Input: m = 2, n = 2
Output: 1
We have the total no of rectangles
= 2C2*2C2
= 1 * 1 = 1
Input: m = 4, n = 4
Output: 36
平面中有“n”个点,其中“m”个点共线。找出由点作为顶点形成的三角形的数量?
Number of triangles = nC3 – mC3
Explanation : Consider the example n = 10, m = 4. There are 10 points, out of which 4 collinear. A triangle will be formed by any three of these ten points. Thus forming a triangle amounts to selecting any three of the 10 points. Three points can be selected out of the 10 points in nC3 ways.
Number of triangles formed by 10 points when no 3 of them are co-linear = 10C3……(i)
Similarly, the number of triangles formed by 4 points when no 3 of them are co-linear = 4C3……..(ii)
Since triangle formed by these 4 points are not valid, required number of triangles formed = 10C3 – 4C3 = 120 – 4 = 116
平面中有“n”个点,其中“m”个点共线,计算连接两点形成的不同直线的数量。
Answer : nC2 – mC2 + 1
Explanation : Number of straight lines formed by n points when none of them are col-linear = nC2
Similarly, the number of straight lines formed by m points when none of them collinear = mC2
m points are collinear and reduce in one line. Therefore we subtract mC2 and add 1.
Hence answer = nC2 – mC2 +1
Examples:
Input : n = 4, m = 3
output : 1
We apply this formula
Answer = 4C2 – 3C2 +1
= 3 – 3 + 1
= 1
更多关于排列组合的练习题:
排列组合测验
组合和排列练习题