[英]Combinatorics: Trying to figure algorithm (about subsets)
I'm trying to solve a problem on TopCoder. 我正在尝试解决TopCoder上的问题。 Basically what I need is algorithms for the following: 基本上我需要的是以下算法:
Let S = [1, 2, ..., n] be a sequence. 令S = [1,2,...,n]为序列。 Let m be less than n. 令m小于n。
1) Find all subsequences of S of size m (which is easy - n^m). 1)找到大小为m的S的所有子序列(这很容易-n ^ m)。
2) Find all subsequences of S of size m where the elements are in nondecreasing order. 2)找到大小为m的S的所有子序列,其中元素按降序排列。
3) Find all subsequences of S of size m where the elements are not allowed to be repeated (which is also easy - (n!)/((nm)!). 3)找到大小为m的S的所有子序列,其中不允许重复元素(这也很容易-(n!)/((nm)!)。
4) Find all subsequences of S of size m where the elements are in nondecreasing order and are not allowed to be repeated. 4)找到大小为m的S的所有子序列,这些元素的顺序为非递减且不允许重复。
Still trying to find formula for parts 2 and 4. A little bit of help will be appreciated. 仍在尝试寻找第2部分和第4部分的公式。将提供一点帮助。
Thanks in advance. 提前致谢。
EDIT: 编辑:
Original problem: 原始问题:
https://docs.google.com/document/d/1X1VK8Vq2DlqMbZpXHGLoWv9ULfRLVoLtMTRRU5nh5qs/edit?usp=sharing https://docs.google.com/document/d/1X1VK8Vq2DlqMbZpXHGLoWv9ULfRLVoLtMTRRU5nh5qs/edit?usp=sharing
to solve 4), note that w/o repetitions 'non-decreasing' means 'increasing'. 解决4),请注意,不重复“不减少”表示“增加”。 partition the set of all sequences of length m
built from S
without repeating elements into equivalence classes defined by the set of elements occurring in the subsequence. 将由S
构建的长度为m
的所有长度序列的集合划分为没有重复元素的等价类,该等价类由子序列中出现的元素集合定义。 within each equivalence class, there is exactly one increasing sequence (elements ordered by <
). 在每个等价类中,只有一个递增的序列(元素按<
排序)。 the size of each equivalence class is the number of permutations of the elements. 每个等价类的大小是元素的排列数量。 the number of 4)-sequences therefore is (n!)/((nm)! * m!) = n \\choose m
. 因此4)序列的数量为(n!)/((nm)! * m!) = n \\choose m
。
ad 2), model the sequence as a sequence of occurrence counts (including 0 for non-inclusion) for all elements in S
. ad 2),将序列建模为S
所有元素的出现次数序列(包括0表示不包含在内)。 this can be written as a sequence of pairs (s_i, k_i), i=1..n; s_i \\in S, k_i \\in IN, \\foreach p,q in {1..n}, p!=q: s_p != s_q
这可以写成成对的序列(s_i, k_i), i=1..n; s_i \\in S, k_i \\in IN, \\foreach p,q in {1..n}, p!=q: s_p != s_q
(s_i, k_i), i=1..n; s_i \\in S, k_i \\in IN, \\foreach p,q in {1..n}, p!=q: s_p != s_q
of length exactly n
. (s_i, k_i), i=1..n; s_i \\in S, k_i \\in IN, \\foreach p,q in {1..n}, p!=q: s_p != s_q
长度为n
(s_i, k_i), i=1..n; s_i \\in S, k_i \\in IN, \\foreach p,q in {1..n}, p!=q: s_p != s_q
。 'non-decreasing' implies a unique permissible ordering of the sequence given by arranging the elements according to increasing s_i
. “不减少”表示通过根据增加s_i
排列元素而给出的序列的唯一允许排序。 thus the only degree of freedom is the occurrence count which must obey the constraint of summing to m: sum_{i=1..n} k_i = m
. 因此,唯一的自由度是必须遵守求和为m的约束的出现次数: sum_{i=1..n} k_i = m
。
this problem is equivalent to partitions with (particular) restrictions and counting lattice paths. 此问题等效于具有(特定)限制并计算晶格路径的分区。 i don't think there is a closed formula for the number of n-tuples from IN^n
meeting this condition. 我不认为满足这种条件的IN^n
的n元组的数量没有封闭的公式。
however, there is a standard algorithm to enumerate all possibilities, eg. 但是,有一种标准算法可以枚举所有可能性,例如。 here 这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.