hello :)

i'm looking for an algo to find out all possible combinations of a 2d array entries, wich are (Tasks x Processors).
i.e, i have to find out all possible schedules to schedule tasks against processors. numbers of tasks and processors are variable.
Suppose :

............P1.......P2.......P3
....................................
T1........3 ........6..........4
T2........5.........1..........7
T3........6.........5..........4
T4........2.........4..........5

(where T=Task and P=Processor)

in above example, obviously, the optimum schedule will be:

T1 -> p1
T2 -> p2
T3 -> p3
T4 -> p1

(where " -> " means, 'should be assigned to')

but i need to find all the possibilities of scheduling. (all possible combinations).
out of all possible combinations, then i'll find the minimum one.
plz guide me :)

Thanks :)

Edited 4 Years Ago by Z33shan

What do the values in the matrix represent? And why is
T1 -> p1
T2 -> p2
T3 -> p3
T4 -> p1
the best? Trying to understand your problem a little more.

can any one help to create an dynamic (2*10) two dimensional array using new and delete?
which ask user to enter the value and fill both row and column?
I am able to create one dimensional but unable to create 2-D.

Look at this

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  //-----------------------------------------------------
  // Setup the size of the matrix
  int rows(3),cols(4),
      **array2D(0),
      i,j;

  try {
     //--------------------------------------------------
     // This will allocate a array of integers pointer, 3
     // in this case
     //
     //  -- 
     // | -|-> null
     //  --
     // | -|-> null
     //  --
     // | -|-> null
     //  --
     //
     array2D = new int* [rows];

     //--------------------------------------------------
     // This one will create the columns, 4 in this case
     //            3 x 4   Matrix
     //  --     -----------
     // | -|-> |  |  |  |  |
     //  --     -----------
     // | -|-> |  |  |  |  |
     //  --     -----------
     // | -|-> |  |  |  |  |
     //  --     -----------
     //
     for ( i=0; i<rows;i++)
        array2D[i] = new int[cols];

     //--------------------------------------------------
     // To fill just loop over rows and columns
     for (i=0;i<rows;i++){
        for (j=0;j<cols;j++){
           cout << "Enter value for position (" << i+1 << "," << j+1 
                << "): "; 
           cin >> array2D[i][j];
        }
     }

     //--------------------------------------------------
     // Print out what was entered
     cout << rows << " x " << cols << " entered: " << endl;
     for (i=0;i<rows;i++){
        for (j=0;j<cols;j++){
           cout << setw(4) << array2D[i][j];
        }
        cout << endl;
     }

     //--------------------------------------------------
     // When you are all done remove the memory.  First 
     // the columns
     for ( i=0; i<rows;i++)
        delete [] array2D[i];

     //--------------------------------------------------
     // Then the row pointers
     delete [] array2D;

  } catch(bad_alloc) {
     cout << "Error:  Out of memory!" << endl;
  }

  return 0;
}
    int num_rows = 10, num_cols = 2;
    int row, col;

    // allocate: a set of rows, then the set of columns for each row
    int **vals = new int * [num_rows];
    for (row = 0; row < num_rows; row++)
        vals[row] = new int [num_cols];

    // delete what you allocated, in reverse order: one "delete" for each "new"
    for (row = 0; row < num_rows; row++)
        delete [] vals[row];
    delete [] vals;
This article has been dead for over six months. Start a new discussion instead.