Ways to place 4 items in n ^ 2 positions such that no row / column contains more than one | C ++ implementation of the approach ; Function to return the number of ways to place 4 items in n ^ 2 positions ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long NumberofWays ( int n ) { long long x = ( 1LL * ( n ) * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) ) / ( 4 * 3 * 2 * 1 ) ; long long y = ( 1LL * ( n ) * ( n - 1 ) * ( n - 2 ) * ( n - 3 ) ) ; return ( 1LL * x * y ) ; } int main ( ) { int n = 4 ; cout << NumberofWays ( n ) ; return 0 ; }