combinatorics

Solution finder algorithm using basic operations

别说谁变了你拦得住时间么 提交于 2019-12-11 03:58:02
问题 I need help with making an algorithm. I am currently designing something for a class I am taking. Given 4 numbers, I need to find all (or at least the first) combination of the 4 numbers using basic operations (+-*/) to make a certain answer. For example, if given numbers [1,2,3,4]. and I have to make the answer 12. I can see (without a program) that (2-1)*3*4 = 12 But for more complex numbers, it may be harder to solve just by thinking about it. So I require a program to help me find at

Getting Least Common Equal Sum and Combination of Two Sets of Numbers

十年热恋 提交于 2019-12-11 03:52:30
问题 I'm currently creating a program in C# that would look for the lowest possible equal sum of two sets of numbers, in which you may repeat the numbers as many times as you want. For example, I have these two sets { 10, 13, 18 } and { 12, 16, 22 } . The lowest possible sum that I can get is 28 : (10 + 18) and (12 + 16) . Another example is {5, 7, 9} and {1, 2, 3} . Lowest possible sum is 5 : (5) and (1+1+1+1+1) or (1+2+2) or (2+3) and so on. Any suggestions on where I can start? I'll actually be

Counting Treaps

こ雲淡風輕ζ 提交于 2019-12-11 03:48:29
问题 Consider the problem of counting the number of structurally distinct binary search trees: Given N, find the number of structurally distinct binary search trees containing the values 1 .. N It's pretty easy to give an algorithm that solves this: fix every possible number in the root, then recursively solve the problem for the left and right subtrees: countBST(numKeys) if numKeys <= 1 return 1 else result = 0 for i = 1 .. numKeys leftBST = countBST(i - 1) rightBST = countBST(numKeys - i) result

Iterative use of bintprog on MATLAB

寵の児 提交于 2019-12-11 02:16:38
问题 We have a problem formulation as shown in this link. Considering that the first call of bintprog gives a solution x that after some post processing does not adequately addresses the physical problem, is it possible to recall bintprog and exclude the prior solution x ? 回答1: You need a nogood cut. Suppose you find a solution \hat{x} that you then decide is infeasible (through some sort of post-processing). Let x and \hat{x} be indexed by i. You can add a constraint of the following form: \sum_

Set ordered partitions in Python of maximum size n

泪湿孤枕 提交于 2019-12-11 02:04:53
问题 I have a problem which is similar to the following but not quite exactly the same: Set partitions in Python So I would like to achieve the same result as this other question, but I would like to block the maximum number of partitions to n , and only get ordered partitions. Also, the values in the partitions should be unique. As an example, the example from the question yielded the following partition for range(1,5) 1 [[1, 2, 3, 4]] 2 [[1], [2, 3, 4]] 3 [[1, 2], [3, 4]] 4 [[1, 3, 4], [2]] 5 [

how to generate possible distinct sets of pairs from a given set?

爷,独闯天下 提交于 2019-12-11 01:31:35
问题 in matlab how do I do this? I have a set of n elements from this set I make a new set of n/2 pairs such that elements in different pairs are distinct. how do I generate distinct sets of such n/2 pairs from n elements in matlab? e.g. input set - {1,2,3,4} possible output sets - {{1,2},{3,4}} {{1,3},{2,4}} {{1,4},{2,3}} 回答1: I could not find a clean solution for the "distinct elements for each halved-vector" requirement. Thus I suggest to check each result individually. I expect that there's a

generating all unique pairs from a list of numbers, n choose 2

。_饼干妹妹 提交于 2019-12-10 21:20:05
问题 i have a list of elements (let's say integers), and i need to make all possible 2-pair comparisons. my approach is O(n^2), and i am wondering if there is a faster way. here is my implementation in java. public class Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public List<Pair> getAllPairs(List<Integer> numbers) { List<Pair> pairs = new ArrayList<Pair>(); int total = numbers.size(); for(int i=0; i < total; i++) { int num1 = numbers.get(i).intValue(); for(int

List all combinations of combinations [duplicate]

微笑、不失礼 提交于 2019-12-10 20:54:51
问题 This question already has answers here : How to split a list into pairs in all possible ways (13 answers) Closed last year . I am trying to list out all the possible combinations of groups of 3 that one can make of 6 people. (A, B, C, D, E, F) The order doesn't of the group doesn't matter The order of the pair doesn't matter Possible combinations: {(B,D),(C,E),(G,H)} {(B,C),(D,E),(G,H)} {(B,E),(C,D),(G,H)} I could only get as far to write: from itertools import combinations x = combinations(

All possible combinations without repetition from an NSArray

梦想的初衷 提交于 2019-12-10 19:29:40
问题 Let say that I have an array with 3 numbers: NSArray *array = @[@1, @2, @3]; And I want to make all combinations without repetition. So what I need is this: ( 1 ) ( 2 ) ( 3 ) ( 1, 2 ) ( 2, 3 ) ( 1, 3 ) ( 1, 2, 3 ) The current code that I have is this: NSArray *array = @[@1, @2, @3]; int numberOfCardsOTable = [array count]; //NSLog(@"array = %@", array); for (int lenghtOfArray = 1; lenghtOfArray <= numberOfCardsOTable; lenghtOfArray++) { for (int i = 0; i < numberOfCardsOTable; i++) { // array

String Combinations With Character Replacement

这一生的挚爱 提交于 2019-12-10 13:58:29
问题 I am trying to work through a scenario I haven't seen before and am struggling to come up with an algorithm to implement this properly. Part of my problem is a hazy recollection of the proper terminology. I believe what I am needing is a variation of the standard "combination" problem, but I could well be off there. The Scenario Given an example string "100" (let's call it x ), produce all combinations of x that swap out one of those 0 (zero) characters for a o (lower-case o). So, for the