How to write out all k-element subsets of n-element set in C?
463145
binary generation or backtracking techniques
348738
A partition of a positive integer n is a set of k strictly positive integers whose sum is n.\n\nHere are the eleven partitions of 6. Observe that they are given in reverse lexicographic order.\n\n{\n {6},\n {5,1},\n {4, 2},\n {4,1,1},\n {3,3},\n {3,2,1},\n {3,1,1,1},\n {2,2,2},\n {2,2,1,1},\n {2,1,1,1,1},\n {1, 1, 1, 1, 1, 1}\n}\n\n\nA set partition of n elements is a grouping of all the elements into nonempty, nonintersecting subsets.\n\nSet partitions are different than integer partitions, representing the ways we can partition distinct elements into subsets. They are useful for representing colorings and clusterings. \n\nSet Partitition of {1,2,3}:\n\n{\n {{1,2,3}},\n {{1}, {2,3}},\n {{1,2}, {3}},\n {{1,3}, {2}},\n {{1}, {2}, {3}}\n}
730115
read KNUTH! that's a classic question.\nhe is the king of algorithms! He wrote the book!\n\n\nbasically sort a pre-sorted list.
805688
U can use either Kruskal's algorithm or prims algorithm. More information about these algorithm u can find on internet.\n\nPrims algorithm is based on adjacency matrix.
964273
If you number the tpopping from 1 to 8, you can have the following combinations of different toppings (numbered for simplicity):\n1) 1, 2, 3\n2) 1, 2, 4\n3) 1, 2, 5\n4) 1, 2, 6\n5) 1, 2, 7\n6) 1, 2, 8\n7) 1, 3, 4\n8) 1, 3, 5\n9) 1, 3, 6\n10) 1, 3, 7\n11) 1, 3, 8\n12) 1, 4, 5\n13) 1, 4, 6\n14) 1, 4, 7\n15) 1, 4, 8\n16) 1, 5, 6\n17) 1, 5, 7\n18) 1, 5, 8\n19) 1, 6, 7\n20) 1, 6, 8\n21) 1, 7, 8\n22) 2, 3, 4\n23) 2, 3, 5\n24) 2, 3, 6\n25) 2, 3, 7\n26) 2, 3, 8\n27) 2, 4, 5\n28) 2, 4, 6\n29) 2, 4, 7\n30) 2, 4, 8\n31) 2, 5, 6\n32) 2, 5, 7\n33) 2, 5, 8\n34) 2, 6, 7\n35) 2, 6, 8\n36) 2, 7, 8\n37) 3, 4, 5\n38) 3, 4, 6\n39) 3, 4, 7\n40) 3, 4, 8\n41) 3, 5, 6\n42) 3, 5, 7\n43) 3, 5, 8\n44) 3, 6, 7\n45) 3, 6, 8\n46) 3, 7, 8\n47) 4, 5, 6\n48) 4, 5, 7\n49) 4, 5, 8\n50) 4, 6, 7\n51) 4, 6, 8\n52) 4, 7, 8\n53) 5, 6, 7\n54) 5, 6, 8\n55) 5, 7, 8\n56) 6, 7, 8\n\nThis means that there are 56 different topping combinations. Since there are 3 types of pizza, 168 (which is 56 * 3) is the number of different pizzas you can choose from here.\n\nAnswer: 168 different pizza type and topping posibilities.
1071317
There are exactly 343 combinations.  I can list them all, but others have already cluttered this thread quite well on their own.  ^.^\n\nYou can think of the solution set as a series of tiered combinations.  These would start with those sets beginning with a $50 bill, which can contain up to 2 x $50,  2 x $20, 5 x $10, etc. which I believe someone has started already in this thread.  Or group them as pairs, triplets, etc. with the equation 50j+20k+10l+5m+1n=100, which may be a bit easier for calculations.  Or a convergent series, where A=(ways to form $5), B=(ways to form $10, including A-sets), etc.  With any method, find the different combinations for each set, then add them all up.\n\nDoing this is still tedious and prone to mistakes, and thus probably not much of an improvement over manually listing all of the combinations one by one.  It can also quickly become an insane exercise for larger values (for example, add the $2 bill, or find change for $200, or even worse).  So instead of trying to think this problem through mathematically, I found it much easier to think it through as a programming problem.  It lends itself very readily to a simple recursive subroutine using the following pseudocode:\n\nmake an empty stack\nset total combinations to 0\ncall CheckCurrency\nprint total combinations found\n\nrecursive subroutine CheckCurrency\n- if total currency in stack = 100\n- - add 1 to the total combinations\n- - (optional: display stack contents)\n- - end recursion\n- if total currency in stack > 100\n- - end recursion\n- if total currency in stack < 100, then\n- - for each valid denomination (50,20,10,5,1)\n- - - if the denomination < = smallest denomination in the stack\n- - - - push it to the stack\n- - - - call CheckCurrency\n- - - - pop it from the stack\nend of subroutine\n\nThis required only a few minutes to design, another few minutes to code, another few minutes to debug, less than 2 seconds to run, and has the wonderful bonus of being able to display every single combination if desired.  It would also be trivial to modify it so that, for example, you can find all combinations if you also include the $2 bill.  (The answer is:  4562 combinations.)  Or to find all combinations totalling $200.  (The answer is: 2930 combinations.)\n\nThe line that checks if the denomination is less than or equal to the smallest denomination currently in the stack is present to avoid a common mistake:  We want the total combinations, not total permutations.  Otherwise, the stack "50 20 20 10" would be counted differently than the stacks "50 20 10 20" and "50 10 20 20", and even "10 20 20 50".  The total permutations is much, much greater, especially if you consider each bill as unique.  Five $20 dollar bills alone have 5!=120 permutations because, after all, they are all completely different $20 bills.  Imagine the number of permutations of 100 x $1 bills, and everything in between.  o.O
483878
Refer to some site dood ... type "difference between difference alloc statements in C" in Y! Search
769460
I think that you want x element of [-6,4)\n\nYou wanted closed on the left and open on the right, is that true?\n\nJust remember that for intervals:\nopen   ( )\nclosed [ ]\n\nAnd you can match them up: [-6,4)
712544
ok so you know 15 can only be broken down to 5*3, -5*-3, 15*1 and -15*-1\ntherefore when you break it up\n(x+3)(x+5) using FOIL (I assume you know how to do that) k would equal 8. For (x-3)(x-5) k would be -8. Do the same for the set of (x+15)(x+1) and (x-15)(x-1)
72054
The following makes a diamond of 41 rows and 41 columns:\nFOR i = -20 TO 20\n FOR j = ABS(i) TO 40 - ABS(i)\n  LOCATE i + 21, j + 1: PRINT "*";\n NEXT j\n PRINT\nNEXT i
147821
- -----------O\n------------ . .-----------  _\n  K+ ( O: Mn  :O )\n-------------. .\n------------ O\n\nomit the long dotted lines
157637
The list may contain more than once the same number.\nthese are all valid lists:\n2 1 3 5 9\n1 1 1\n-5 0 -5 0 -5 1 5\n\nThe algorithm will be O(n) (you have to examine every element at least once and once is enough).\nc code would be something like this\n\nint *find_last_min(int *list, int length)\n{\n  int i, *min = list; /* assuming the list is not empty */\n  for(i = 1; i < length; ++i)\n    if(*min >= list[i])\n      min = list + i;\n  return min;\n}
274717
for( int i = 55; i > 0; i-- )\n  printf( "%d&#92;n", i );
331637
hahaha. do it yourself. ill start you off.\nfirst write out the 5 possibilities of the first letter. then for each letter, write out the 4 possibilities of the 2nd letter. then for each of those combinations, write out the 3 possibilities of the 3rd letter and for each of those write otu the 2 possibilities of the 4th letter and then theres only 1 possibility of the last letter for each of them.\n\nF L A S H\nF L A H S\nF L S A H\nF L S H A\nF L H A S\nF L H S A\nF A L S H\nF A L H S\nF A S L H\nF A S H L\nF A H L S\nF A H S L\nF S L A H\nF S L H A\nF S A L H\nF S A H L\nF S H L A\nF S H A L\nF H L A S\nF H L S A\nF H A L S\nF H A S L\nF H S L A\nF H S A L\n\nL F\n  A\n  S\n  H\n\nA F\n  L\n  S\n  H\n\nS F\n  L\n  A\n  H\n\nH F\n  L\n  A\n  S
691515
algorithms, data structures, computer organization
973
u spelt it wrong :-(\nit should have been Dijikstra\n\nSTDMETHODIMP CDijkstra::ShortestPath(long node1, long node2)\n{\n    ReleaseGraph();\n    // init d and pi\n    InitializeSource(g, g.m_nodes[node1-1]);\n    // Set S empty\n    VTYPE_NODE S;\n    // Put nodes in Q\n    VTYPE_NODE Q;\n    VTYPE_NODE::iterator kl;\n    for(kl=g.m_nodes.begin(); kl<g.m_nodes.end(); kl++)\n    {\n        CNode node = (*kl).Copy();\n        Q.push_back(node);\n    }\n    // Algorithm\n    while(Q.size())\n    {\n        CNode nod = ExtractMin(Q); // the minim value \n                // for the shortest path up to this step\n        S.push_back(nod);\n        // each vertex v which is a neighbour of u\n        VTYPE_NODE::iterator kl;\n        for(kl=g.m_nodes.begin(); kl<g.m_nodes.end(); kl++)\n        {\n            if(ExistEdge(nod, (*kl)))\n            {\n                bool gasit = false;\n                VTYPE_NODE::iterator kll;\n                for(kll=Q.begin(); kll<Q.end(); kll++)\n                {\n                    if((*kll).m_NodeNr == (*kl).m_NodeNr)\n                    gasit = true;\n                }\n                if(gasit)\n                    Relax(nod, (*kl), GetEdgeVal(nod, (*kl)));\n            }\n        }\n    }\n    RefreshDone(node1, node2);\n    return S_OK;\n}
280441
http://www.cs.ucdavis.edu/~haungs/paper/node11.html