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
-
341 Solvers
-
129 Solvers
-
Remove from a 2-D matrix all the rows that contain at least one element less than or equal to 4
134 Solvers
-
Remove entire row and column in the matrix containing the input values
318 Solvers
-
Matrix multiplication across rows
304 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!