#K78172. Valid Molecule Placement in Grid
Valid Molecule Placement in Grid
Valid Molecule Placement in Grid
You are given an n by m grid. Your task is to count the number of valid ways to place exactly k molecules 'A' into the grid such that no two 'A' molecules share the same row or column.
This is equivalent to selecting k rows from n available rows and k columns from m available columns, then arranging the k molecules in these positions in a one-to-one manner. Mathematically, the answer can be expressed as:
$$ \binom{n}{k} \times \binom{m}{k} \times k! $$
If k
is greater than either n
or m
, then it is impossible to place the molecules and the answer is 0.
inputFormat
The input consists of a single line containing three space-separated integers: n m k
, where n
and m
are the dimensions of the grid and k
is the number of molecules to place.
outputFormat
Output a single integer which is the number of valid configurations.
## sample2 2 2
2