- 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

In this problem, we are given an integer n such that there are n lines vertically and n horizontally that are placed such that there are n2 intersection between these lines. Our task is to find the total number of ways by which 4 items can be placed on these intersections in

such a way that no row and column contains more that one item.

Let’s take an example to understand the problem,

n=4

24

To solve this problem, we will have to choose 4 horizontal lines from n lines that will have items which will be nC4. Now, every horizontal line has n vertical lines so, there will be n way to place an item in the first selected horizontal line. Then, we will move to the next selected horizontal line where there will be n-1 possible placements. And it the same way third could be placed in n-2 and forth in n-3 ways. So, the total number of wats will be ^{n}C4*n*(n-1)*(n-2)*(n-3)

Program to show the implementation of the algorithm,

#include <iostream> using namespace std; long long placeItems(int n) { return (1LL * (1LL * ((n) * (n - 1) * (n - 2) * (n - 3)) / (4 * 3 * 2 * 1)) * ((1LL * (n) * (n - 1) * (n - 2) * (n - 3)))); } int main() { int n = 4; cout<<"The number of way is which 4 items can be placed in the intersection of "<<n; cout<<" lines vertically and horizotally are "<<placeItems(n); return 0; }

The number of way is which 4 items can be placed in the intersection of 4 lines vertically and horizotally are 24

- Related Questions & Answers
- Place N^2 numbers in matrix such that every row has an equal sum in C++
- Select MySQL rows where column contains same data in more than one record?
- Maximum sum in a 2 x n grid such that no two elements are adjacent in C++
- Maximum sum such that no two elements are adjacent - Set 2 in C++
- MySQL search if more than one string contains special characters?
- Find maximum N such that the sum of square of first N natural numbers is not more than X in C++
- Balanced expressions such that given positions have opening brackets in C++?
- C++ Balanced expressions such that given positions have opening brackets
- How to sort more than one column at a time in MySQL?
- MySQL query to include more than one column in a table that doesn't already exist
- Find maximum N such that the sum of square of first N natural numbers is not more than X in Python
- Place k elements such that minimum distance is maximized in C++
- Array elements that appear more than once in C?
- Print n 0s and m 1s such that no two 0s and no three 1s are together in C Program
- Print an N x M matrix such that each row and column has all the vowels in it in C++

Advertisements