@gsdev99

Как решить следующую задачу?

Всем привет. Недавно увидел такую задачу. Но возникли сложности с решением. Был бы благодарен вашей помощи.

There are m men and w women. A deputation of exactly 3 people has to be formed from them. A deputation is diverse if and only if it contains at least one man and at least one woman. How many distinct ways are there to select a diverse deputation of 3 people? Two deputations are different if and only if one deputation has a member which the other does not have.
Find the number of ways to select a diverse deputation of 3 people.

Function Description
Complete the function diverseDeputation in the editor below. The function must return an integer which is the number of ways to select a diverse deputation from m men and w women.

Constraints
0 ≤ m, w ≤ 1000

/*
* Complete the 'diverseDeputation' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER m
* 2. INTEGER w
*/

function diverseDeputation(m, w) {
// Write your code here
}
  • Вопрос задан
  • 214 просмотров
Пригласить эксперта
Ответы на вопрос 1
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
А в чём проблема?
количество_разных_пар_мужчин * количество_женщин + количество_разных_пар_женщин * количество_мужчин
(m * (m - 1) / 2) * w + (w * (w - 1) / 2) * m =
= (m * w * (m + w - 2)) / 2
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы