- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find the Number of Ways to Pair People using C++

To solve a problem in which n − the number of people now each person can either be single or be present in a pair, so we need to find the total number of ways these people can be paired up.

Input : 3 Output: 4 Explanation : [ {1}, {2}, {3},], [{1, 2}, {3}], [{1}, {2, 3}], [{1, 3}, {2}] these four ways are the only ways we can pa up these 3 people. Input : 6 Output : 76

## Approach to Find the Solution

In this approach, we are going to use the formula of **Young Tableau** to calculate this problem and the formula that we are going to use is −

A[n] = A[n-1] + (n-1) * A[n-2]

## Example

**C++ Code for the Above Approach**

#include <bits/stdc++.h> using namespace std; int Young_Tableau(int n){ int A[n + 1];// To store the answer. A[1] = 1; // initial values A[2] = 2; // initial values for (int i = 3; i <= n; i++) { // using the formula of "Young Tableau" to calculate our answer A[i] = A[i - 1] + (i - 1) * A[i - 2]; } return A[n]; // returning the answer } int main(){ int n = 6; cout << Young_Tableau(n); return 0; }

## Output

76

## Explanation of the Above Code

**In the above approach, we simply apply the formula for Young Tableau, where we need to find** the previous two numbers. Now we can store these numbers in array indices. By subscribing, we can attain their values for our formula, and hence we calculate our answer.

## Conclusion

In this tutorial, we solve a problem to find several ways to pair people. We also learned the C++ program for this problem and the complete approach (Normal) by which we solved this problem. We can write the same program in other languages such as C, java, python, and other languages. We hope you find this tutorial helpful.

- Related Questions & Answers
- Find the Number of Ways to Traverse an N-ary Tree using C++
- Program to find out the number of people who get a food packet using Python
- Find the Number of Ways to go From One Point to Another in a Grid using C++
- Program to find minimum number of people to teach in Python
- Find the number of zeroes using C++
- Program to find number of good ways to split a string using Python
- C++ Program to Find the Number of Ways to Write a Number as the Sum of Numbers Smaller than Itself
- Best ways to discover people to talk on twitter
- Count ways of choosing a pair with maximum difference in C++
- Find if two people ever meet after same number of jumps in C++
- Find the Number of Stopping Stations using C++
- Find the number of stair steps using C++
- Find the slope of the given number using C++
- Program to find number of ways we can reach to the next floor using stairs in Python
- Find the Number of Solution to Modular Equations using C++