- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Entringer Number in C++
Entringer Number is a special number which is equal to the number of permutations of {1, 2, 3, … n+1}, starting with K+1 which is updated by decreasing then increasing the values alternatively.
The value of Entringer Number is formulated using,
The recurrence relation,
E(n, k) = E(n, k-1) + E(n-1, n-k)
The base value is,
E(0,0) = 1
E(n, 0) = 0
We can find the Entringer number using,
Let’s take an example to see values
N = 5, k = 3
E(5, 3) = 14
Program to illustrate the working of our solution,
Example
#include <iostream> using namespace std; int EntringerNumber(int n, int k) { if (n == 0 && k == 0) return 1; if (k == 0) return 0; return EntringerNumber(n, k - 1) + EntringerNumber(n - 1, n - k); } int main() { int n = 5, k = 3; cout<<"The value of E("<<n<<", "<<k<<") = "<<EntringerNumber(n, k); return 0; }
Output −
The value of E(5, 3) = 14
Advertisements