![]() |
|
#1
|
|||
|
|||
combinations of elements on vectorsHi friends,
I have a vector x={1,2,2} and I want to obtain its combinations i.e. y={{1,1,1},{1,1,2},{1,2,1},{1,2,2}} Here is a sample of the program, we can see the amount of combinations with this... CPP / C++ / C Code:
Can someone give a suggestion to do it? regards, CPIT Last edited by cpit : 27-Sep-2006 at 12:44.
Reason: improved explanation
|
|
#2
|
|||
|
|||
Re: combinations of elements on vectorsHmmm... bit lost here. How is {1,1,1} a combination of {1,2,2}? What are you using the results for?
__________________
Michael Dual Opteron 280 (2 x dual core) with 2Gb RAM, 2x36GB system drives, 2T on 3Ware 9500Mi RAID controller. Running Fedora Core 4. Using Anjuta IDE. Developemnt in C++ with MySQL (via mysql++). |
|
#3
|
|||
|
|||
Re: combinations of elements on vectorsOK Friend,
I will try to explain better... I´m going use this for to implement all possible routes in a network. I made a modification on Dijkstra´s algorithm to find all shortest paths between two nodes. Then, imagine a network with 4nodes and connected like this: 1-2 or be, node1 have a link to connect node2... 1-3 2-4 3-4 After perform the algorithm to find out all shortest paths we have 2 routes from the node 1 to node 4, and 2 routes from the node 2 to 3. then, we can set a matrix of paths like this: - 1 1 2 1 - 2 1 1 2 - 1 2 1 1 - and using the number above the main diagonal, we have 1 1 2 2 1 1 Now I need to perform other calcs on each combination of traffic. then 1 1 1 1 1 1 means that I will use a set of paths and 1 1 1 2 1 1 means that I will use other set of paths and 1 1 2 1 1 1 and 1 1 2 2 1 1 In this simple case we have only 4 combinations, but I want to tread large networks, for example, with more than 100 nodes!!! Regards, CPIT |
Recent GIDBlog
I?m Home by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Deleting elements of arrays C++ | the_crazyman | C++ Forum | 25 | 30-May-2008 08:27 |
| Vectors and inserting elements | Krandygrl00 | C++ Forum | 2 | 07-Jun-2005 14:14 |
| vectors of references | mirizar | C++ Forum | 1 | 12-Apr-2005 03:02 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 22:26 |
| Declaring a vector of vectors? | Lethal411 | C++ Forum | 2 | 20-Mar-2004 10:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The