Problem 56250. Counting Permutations
In the permutations of the numbers 1 to n, count the number of permutations in which exactly m elements are greater than the previous element.
Example -
n=4;
m=2;
%permutations in which exactly 2 numbers are greater than the previous element
y=[1 3 2 4
1 4 2 3
1 2 4 3
2 3 1 4
4 1 2 3
2 4 1 3
2 1 3 4
1 3 4 2
2 3 4 1
3 1 2 4
3 4 1 2]
%11 permutations
out=11;
n=3;
m=0;
%permutations in which exactly 0 numbers are greater than the previous element
y=[3 2 1];
%only 1 permutation
out=1;
n=3;
m=1;
%permutations in which exactly 1 numbers are greater than the previous element
y=[1 2 3
1 3 2
2 3 1
2 1 3];
%4 permutations
out=4;
n=3;
m=2;
%permutations in which exactly 2 numbers are greater than the previous element
y=[1 2 3];
%only 1 permutation
out=1;
The task, here, is to calculate the output for all values of m (0 to n-1) given a natural number n, and output it in a row vector.
Check test case #1 for restricted functions.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers6
Suggested Problems
-
2355 Solvers
-
Two-output anonymous function?
79 Solvers
-
432 Solvers
-
81 Solvers
-
Solving Quadratic Equations (Version 1)
495 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!