permutation

C++ STL Next Permutation with Combination

一世执手 提交于 2019-12-21 09:30:10
问题 I know that I can use std::next_permutation on some container containing the elements [1, 2, 3] which would generate 6 permutations of this sequence. What I would like to do is given some set [1, 2, 3, 4, 5, 6] generate all possible permutations of size 3. So for this example, [4, 3, 2] would be one of the permutations resulting from this criteria. I'm looking for an STL way of doing this (if possible) rather than writing my own combinations function. Any particular STL implementation I

AI algorithm for multi dimension solution optimization / prediction

时光总嘲笑我的痴心妄想 提交于 2019-12-21 06:44:34
问题 I have 6 int parameters ranging from 0 to 100 The total combination of the numbers are 100^6 and each combination gives a result ranging approx. from -10000 to 100000 or even more. Input data example: MySimulation (57, 78, 20, 10, 90, 50) = 300 <- Best Result MySimulation (50, 80, 10, 90, 35, 8) = 200 MySimulation (4, 55, 40, 99, 40, 50) = -50 <- Worst Result The higher the result the better the combination of numbers are, I already have the calculation which gives a result, I only need AI to

AI algorithm for multi dimension solution optimization / prediction

别等时光非礼了梦想. 提交于 2019-12-21 06:44:27
问题 I have 6 int parameters ranging from 0 to 100 The total combination of the numbers are 100^6 and each combination gives a result ranging approx. from -10000 to 100000 or even more. Input data example: MySimulation (57, 78, 20, 10, 90, 50) = 300 <- Best Result MySimulation (50, 80, 10, 90, 35, 8) = 200 MySimulation (4, 55, 40, 99, 40, 50) = -50 <- Worst Result The higher the result the better the combination of numbers are, I already have the calculation which gives a result, I only need AI to

Stuck with Combination Problem

旧街凉风 提交于 2019-12-21 06:44:02
问题 I'm having a problem w/ my program. I have extracted a set of data and I would like to test if there is a combination for a particular number. For example, I have an array of int, 1 2 3 4 5, I would like to know if there is a combination for 7 maybe, and it must answer yes there is 3 + 4. I figured out that I need to use the combination formula. So I thought that the outer loop may go like 5C1..5C2..5C3..etc, starting to "take 1" then "take 2" at a time to find out all the possible

Stuck with Combination Problem

若如初见. 提交于 2019-12-21 06:43:14
问题 I'm having a problem w/ my program. I have extracted a set of data and I would like to test if there is a combination for a particular number. For example, I have an array of int, 1 2 3 4 5, I would like to know if there is a combination for 7 maybe, and it must answer yes there is 3 + 4. I figured out that I need to use the combination formula. So I thought that the outer loop may go like 5C1..5C2..5C3..etc, starting to "take 1" then "take 2" at a time to find out all the possible

Check if two arrays are cyclic permutations

假装没事ソ 提交于 2019-12-21 03:57:23
问题 Given two arrays, how do you check if one is a cyclic permutation of the other? For example, given a = [1, 2, 3, 1, 5] , b = [3, 1, 5, 1, 2] , and c = [2, 1, 3, 1, 5] we have that a and b are cyclic permutations but c is not a cyclic permutation of either. Note: the arrays may have duplicate elements. 回答1: The standard trick here is to concatenate one of the arrays with itself, and then try to find the 2nd array in the concatenated array. For example, 'a' concatenated with itself is: [1, 2, 3

Permutations with MapReduce

一笑奈何 提交于 2019-12-21 02:41:38
问题 Is there a way to generate permutations with MapReduce? input file: 1 title1 2 title2 3 title3 my goal: 1,2 title1,title2 1,3 title1,title3 2,3 title2,title3 回答1: Since a file will have n inputs, the permutations should have n^2 outputs. It makes sense that you could have n tasks perform n of those operations. I believe you could do this (assuming only for one file): Put your input file into the DistributedCache to be accessible as read-only to your Mapper/Reducers. Make an input split on

Counting all permutations of a string (Cracking the Coding Interview, Chapter VI - Example 12)

谁都会走 提交于 2019-12-20 19:47:22
问题 In Gayle Laakman's book "Cracking the Coding Interview", chapter VI (Big O), example 12, the problem states that given the following Java code for computing a string's permutations, it is required to compute the code's complexity public static void permutation(String str) { permutation(str, ""); } public static void permutation(String str, String prefix) { if (str.length() == 0) { System.out.println(prefix); } else { for (int i = 0; i < str.length(); i++) { String rem = str.substring(0, i) +

Why Time complexity of permutation function is O(n!)

一个人想着一个人 提交于 2019-12-20 19:44:06
问题 Consider following code. public class Permutations { static int count=0; static void permutations(String str, String prefix){ if(str.length()==0){ System.out.println(prefix); } else{ for(int i=0;i<str.length();i++){ count++; String rem = str.substring(0,i) + str.substring(i+1); permutations(rem, prefix+str.charAt(i)); } } } public static void main(String[] args) { permutations("abc", ""); System.out.println(count); } } here the logic, that i think is followed is- it considers each character

Smart way to generate permutation and combination of String

风格不统一 提交于 2019-12-20 09:49:05
问题 String database[] = {'a', 'b', 'c'}; I would like to generate the following strings sequence, based on given database . a b c aa ab ac ba bb bc ca cb cc aaa ... I can only think of a pretty "dummy" solution. public class JavaApplication21 { /** * @param args the command line arguments */ public static void main(String[] args) { char[] database = {'a', 'b', 'c'}; String query = "a"; StringBuilder query_sb = new StringBuilder(query); for (int a = 0; a < database.length; a++) { query_sb