Insertion sort is a simple sorting algorithm that builds the final sorted array one item at an iteration.
More precisely, insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.
At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
It repeats until no input elements remain.
This type of sorting is typically done in-place, by iterating up the array, growing the sorted array behind it.
At each array-position, it checks the value there against the largest value in the sorted array (which happens to be next to it, in the previous array-position checked).
If larger, it leaves the element in place and moves to the next.
If smaller, it finds the correct position within the sorted array, shifts all the larger values up to make a space, and inserts into that correct position.
The resulting array after $k$ iterations has the property where the first $k$ entries are sorted.
In each iteration the first remaining entry of the input is removed, and inserted into the result at the correct position, thus extending the result.
Knuth is an ACM-ICPC master and provides a modified pseudocode implementation about the insertion sort for you.
His modified algorithm for an array of sortable items $A$ ($1$-based array) can be expressed as:
Given the parameter $k$, you are asked to count the number of distinct permutations of $1$ to $n$ meeting the condition that, after his modified insertion sort, each permutation would become an almost sorted permutation.
Here he notes that a permutation of $1$ to $n$ is almost sorted if the length of its longest increasing subsequence is at least $(n - 1)$.