I'm trying to solve a problem on TopCoder. Basically what I need is algorithms for the following:
Let S = [1, 2, ..., n] be a sequence. Let m be less than n.
1) Find all subsequences of S of size m (which is easy - n^m).
2) Find all subsequences of S of size m where the elements are in nondecreasing order.
3) Find all subsequences of S of size m where the elements are not allowed to be repeated (which is also easy - (n!)/((n-m)!).
4) Find all subsequences of S of size m where the elements are in nondecreasing order and are not allowed to be repeated.
Still trying to find formula for parts 2 and 4. A little bit of help will be appreciated.
Thanks in advance.
EDIT:
Original problem:
https://docs.google.com/document/d/1X1VK8Vq2DlqMbZpXHGLoWv9ULfRLVoLtMTRRU5nh5qs/edit?usp=sharing