- 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

Given n, r, k, now we have to find how we can select r things from n so that specific k things always occur together, for example.

Input : n = 8, r = 5, k = 2 Output : 960 Input : n = 6, r = 2, k = 2 Output : 2

We need a little knowledge for this problem because this problem is asking us to find the permutation of n and r such that k things come together.

We need to formulate our formula for this question, and that will give us our answer.

#include <bits/stdc++.h> using namespace std; int fact(int n){ // function to calculate factorial of a number if(n <= 1) return 1; return n * fact(n-1); } int npr(int n, int r){ // finding permutation int pnr = fact(n) / fact(n - r); return pnr; } int countPermutations(int n, int r, int k){ // the formula that we came up with return fact(k) * (r - k + 1) * npr(n - k, r - k); } int main(){ int n = 8; int r = 5; int k = 2; cout << countPermutations(n, r, k); return 0; }

960

In the above approach, we try to devise our formula for calculating our answer as for this problem, the formula that we devised is (k!) * (r - k + 1) * P(n-k, r-k). ( P(x, y) is the number of permutations of selection y from x) hence we put up our formula, and we calculate the answer.

In this tutorial, we solve a problem to find Permutations of n things taken r at a time with k things together. 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
- The Internet of Nano Things
- Defining internet of things iot for businesses
- Things that make you less productive
- Wireless Media Access Issues in Internet of Things
- Things to Know Before You Start a Blog
- What is the introduction of Cloud of Things (CoT)?
- What is the Architecture of Internet of Things (IoT)?
- How Blockchain technology can benefit the Internet of things?
- What are the things money cannot buy?
- Ten Things to Know About Google Glass
- How to overcome laziness and the habit of postponing things?
- What do you mean by Internet of Things (IoT) Gateways?
- Why do things become black after burning them?
- What are the things that make Indians sad?
- Why do we forget things? Is it normal?

Advertisements