- 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

# Ways to place items in n^2 positions such that no row/column contains more than one in C++

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,

## Input

n=4

## Output

24

## Explanation

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,

## Example

#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; }

## Output

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++
- MySQL search if more than one string contains special characters?
- Maximum sum such that no two elements are adjacent - Set 2 in C++
- 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
- Find maximum N such that the sum of square of first N natural numbers is not more than X in C++
- JavaScript array: Find all elements that appear more than n times
- Program to find number of ways we can arrange letters such that each prefix and suffix have more Bs than As in Python
- How to select more than one row at a time in a JTable with Java?
- How to specify that a user can enter more than one value in HTML?
- Balanced expressions such that given positions have opening brackets in C++?
- How to concatenate more than 2 fields with SQL?