combinatorics

Calculate Nth multiset combination (with repetition) based only on index

谁说我不能喝 提交于 2019-12-19 10:19:35
问题 How can i calculate the Nth combo based only on it's index. There should be (n+k-1)!/(k!(n-1)!) combinations with repetitions. with n=2, k=5 you get: 0|{0,0,0,0,0} 1|{0,0,0,0,1} 2|{0,0,0,1,1} 3|{0,0,1,1,1} 4|{0,1,1,1,1} 5|{1,1,1,1,1} So black_magic_function(3) should produce {0,0,1,1,1}. This will be going into a GPU shader, so i want each work-group/thread to be able to figure out their subset of permutations without having to store the sequence globally. with n=3, k=5 you get: i=0, {0,0,0,0

Calculate the index of a given number within a sorted set

谁都会走 提交于 2019-12-19 10:04:03
问题 Not sure if this question should be on Math-Overflow or here, so will try here first: Suppose we are given a number with N 1s and M 0s. There are (M+N)!/(M!*N!) different such numbers, that can be sorted in a countable set. For example, the sorted set of all numbers with 2 ones and 3 zeros, is: 0 00011 1 00101 2 00110 3 01001 4 01010 5 01100 6 10001 7 10010 8 10100 9 11000 How can we efficiently calculate the index of a given number within the corresponding set? Note: the input to this

All possible combinations of a given string

百般思念 提交于 2019-12-19 09:49:42
问题 I need to find all possible combinations of a given string, from a minimum length to a maximum length. interface allCombos(string: String, min: Number, max:Number): Array {} So if my input string is ‘abcde’ , and my minimum length is 3, I want the result to be: For length 3: [‘abc’, ‘abd’, ‘abe’, ‘acd’, ..., ‘bcd’, ‘bce’, ..., ‘eda’, ...] Concatenated with length 4: [‘abcd’, ‘abdc’, ‘acdb’, ‘acbd’, …etc] Concatenated with all possible combinations with length up to the max parameter. Which

Number of different binary string with k flips

六月ゝ 毕业季﹏ 提交于 2019-12-19 09:38:19
问题 I am trying a problem where we are given binary string of length N(<10^5), and we are allowed exactly X(<10^5) flips on it, we are asked how many different string is possible? I am not getting idea about this, i though that it might be solved using dp, but not able to come with a recursion. Plz Help? Example: consider the binary string of N = 3 , 1 1 1 , and X = 2 New Binary strings that can be formed after applying 2 flips are 1 1 1 (flipped the first/second/third bit twice) 0 0 1 (flipped

Number of different binary string with k flips

走远了吗. 提交于 2019-12-19 09:38:14
问题 I am trying a problem where we are given binary string of length N(<10^5), and we are allowed exactly X(<10^5) flips on it, we are asked how many different string is possible? I am not getting idea about this, i though that it might be solved using dp, but not able to come with a recursion. Plz Help? Example: consider the binary string of N = 3 , 1 1 1 , and X = 2 New Binary strings that can be formed after applying 2 flips are 1 1 1 (flipped the first/second/third bit twice) 0 0 1 (flipped

Finding cheapest combination of items with conditions on the selection

倖福魔咒の 提交于 2019-12-19 07:43:26
问题 Lets say that I have 3 sellers of a particular item. Each seller has different amounts of this items stored. The also have a different price for the item. Name Price Units in storage Supplier #1 17$ 1 Unit Supplier #2 18$ 3 Units Supplier #3 23$ 5 Units If I do not order enough items from the same supplier, I have to pay some extra costs per unit . Let's say, for example, that if I do not order at least 4 units, I do have to pay extra 5$ for each unit ordered. Some examples: If I wanted to

Finding cheapest combination of items with conditions on the selection

情到浓时终转凉″ 提交于 2019-12-19 07:42:14
问题 Lets say that I have 3 sellers of a particular item. Each seller has different amounts of this items stored. The also have a different price for the item. Name Price Units in storage Supplier #1 17$ 1 Unit Supplier #2 18$ 3 Units Supplier #3 23$ 5 Units If I do not order enough items from the same supplier, I have to pay some extra costs per unit . Let's say, for example, that if I do not order at least 4 units, I do have to pay extra 5$ for each unit ordered. Some examples: If I wanted to

Weekly group assignment algorithm with odd number of participants

前提是你 提交于 2019-12-19 05:01:10
问题 There is a round-robin solution to a question I asked before. It works great with even number of people but none of the suggestions seem to work once you implement the algorithm and try them out. I've tried many variations and (grouping the last one with a whole bunch of other people, the second group the last group, different combinations, the 2 and 4 to the last of the bottom row, I thought this would give me the most optimal solution but still many duplicates). Can someone suggest a way to

Weekly group assignment algorithm with odd number of participants

最后都变了- 提交于 2019-12-19 04:58:04
问题 There is a round-robin solution to a question I asked before. It works great with even number of people but none of the suggestions seem to work once you implement the algorithm and try them out. I've tried many variations and (grouping the last one with a whole bunch of other people, the second group the last group, different combinations, the 2 and 4 to the last of the bottom row, I thought this would give me the most optimal solution but still many duplicates). Can someone suggest a way to

Combinatorics in Python

自闭症网瘾萝莉.ら 提交于 2019-12-19 03:16:29
问题 I have a sort of a one level tree structure as: Where p are parent nodes, c are child nodes and b are hypothetical branches. I want to find all combinations of branches under the constraint that only one parent can branch to only one child node, and two branches can not share parent and/or child. E.g. if combo is the set of combinations: combo[0] = [b[0], b[3]] combo[1] = [b[0], b[4]] combo[2] = [b[1], b[4]] combo[3] = [b[2], b[3]] I think that's all of them. =) How can this be achived