combinations

How to get different grouping combinations from a list

╄→гoц情女王★ 提交于 2019-12-12 04:22:26
问题 I'm working on a problem where I want to group a list by two's and get all possible combinations. for example: for the list [A,B,C,D]; I'm trying to create a method that will give me the ff: A and BCD B and ACD C and ABD D and ABC AB and CD AC and BD AD and BC etc... I know that recursion is the answer but I don't know where to start. Can someone point me to the right direction? My attempt so far: List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"

Python: combinations of map tuples

烂漫一生 提交于 2019-12-12 04:05:29
问题 I have a list of maps in Python looking like this: 2: a, b 3: b, c, d 4: a And I want to create all conbinations of key-value-pairs, i.e.: (2,a)(3,b)(4,a) (2,a)(3,c)(4,a) (2,a)(3,d)(4,a) (2,b)(3,b)(4,a) (2,b)(3,c)(4,a) (2,b)(3,d)(4,a) I neither know the size of the maps nor the size of the list, but the list will never have more than 4 elements. I can assume that the keys are unique but not that they are always 1,2,3,4 or 0,1,2,3 as depicted in the example above. What is the smartest/most

producing m-member combination in a n-member array [duplicate]

这一生的挚爱 提交于 2019-12-12 03:53:50
问题 This question already has answers here : Generating combinations in c++ (13 answers) Closed 3 years ago . I have an array with n members. And I have another number: m ,( m <= n ) which is entered by user. Now I want to produce all of possible "m" member combination in the array. A[5] = {a,b,c,d,e}; B = 3 Number of combination: C(5, 3) = 10 Now I want a code for showing these 10 combination.like: {{a,b,c},{a,b,d},{a,b,e},.....} Order of items in permutation is important. For example {a,b,d} is

Combinations of multiple list

匆匆过客 提交于 2019-12-12 03:43:27
问题 I'm not completely sure that the term 'Combination' is correct, however I have a requirement to build a list of combination form one or more List. Each list will contain a varying number of elements, e.g. List<string> lBag1 = ["1_0, 1_1, 1_3"] List<string> lBag2 = ["11_0, 11_1, 11_8"] List<string> lBag3 = ["3_0"] What I need is all combination of the Lists form 1 to n elements with no more than one element from each list, e.g. "1_0" "1_1" "1_3" "11_0" "11_1" "11_8" "3_0" "1_0 11_0" "1_0 11_1"

Generate all combinations in bit version

耗尽温柔 提交于 2019-12-12 03:37:41
问题 I'd like to generate all possible combination (without repetitions) in bit representation. I can't use any library like boost or stl::next_combination - it has to be my own code (computation time is very important). Here's my code (modified from ones StackOverflow user): int combination = (1 << k) - 1; int new_combination = 0; int change = 0; while (true) { // return next combination cout << combination << endl; // find first index to update int indexToUpdate = k; while (indexToUpdate > 0 &&

Matlab: how to build a combination according to the logical 0 and 1 but by adding 100?

左心房为你撑大大i 提交于 2019-12-12 03:23:07
问题 From the vector V=[3 31 40] , how to find the following combination: 3 31 40 3 31 140 3 131 40 3 131 140 103 31 40 103 31 140 103 131 40 103 131 140 the construction is done by following the logic of the combination of 0 and 1 , but by adding 100 回答1: Using this: V=[3 31 40] ; comb = dec2bin((0:2^numel(V)-1).') ; %'// generate all the possible binary combinations cl = logical( double(comb)-48 ) ; %// translate them to an array of logical Vout = repmat( V , size(cl,1),1 ) + cl.*100 ; %//

Algorithm to generate all combinations of a string with length n to 1 [closed]

女生的网名这么多〃 提交于 2019-12-12 03:07:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am looking for help with an algorithm that will generate all the possible combinations of n-random letters in decreasing length. For example, the array of 'a','b','c' should generate: abc acb bac bca cab cba ab ac ba bc ca cb a b c where letters cannot repeat themselves once used 回答1: "Permutation with

Generate all Letter Combinations [closed]

北慕城南 提交于 2019-12-12 02:54:52
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Can someone help me get a C algorithm to generate all letter combinations of length n? I need the output to be like: aaaaaaa aaaaaab aaaaaac . . . zzzzzzx zzzzzzy zzzzzzz for(i = 0; i<length; i++){ pass[i] = 'a';

PHP array combination with Left to Right order [duplicate]

一曲冷凌霜 提交于 2019-12-12 02:46:25
问题 This question already has answers here : Display possible combinations of string (3 answers) Closed 4 years ago . I have a PHP array that looks like this $alphabet= array('a','b','c') $alphabet is a input i need a result like $result Expected output: $result= array( [0]=> "a" [1]=> "b" [2]=> "c" [3]=> "ab" [4]=> "ac" [5]=> "bc" [6]=> "abc" ) Note: here, I would not like sorting to use. Thanks! 回答1: Use usort and costum sort function: $array = array("a", "bc", "bb", "aa", "cc", "bb"); function

Enumerating distibutions

时光总嘲笑我的痴心妄想 提交于 2019-12-12 02:02:54
问题 I'm trying to create a text file with every possible distribution of 100% into n containers? So that for 4 containers, it would look something like this: 0.97, 0.01, 0.01, 0.01 0.96, 0.01, 0.01, 0.02 0.96, 0.01, 0.02, 0.01 0.96, 0.02, 0.01, 0.01 ... Any ideas on a good way to accomplish this? 回答1: Based on your response in the comments above, here's a recursive solution in Ruby: $resolution = 100 $res_f = $resolution.to_f def allocate(remainder, bin_number, all_bin_values, number_of_bins) if