Thread: permutation of a 2D integer array.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    4

    Post permutation of a 2D integer array.

    I need to get find the maximum possible sum of a 2D array, but can only use one number per row/column (similar to the Hungarian Method). I've been working on the code for quite some time, but I haven't gotten far. I'm fairly new to programming, so the explanations online are far above my knowledge of the C language.
    I don't really have much, but here it is:

    Code:
    
    int permute(int mmin[10][10], int size){
    int q, total=0, sum=0;
    
    
    
    
       for(q=size;q>=0;q--){
    
    
    
    
        mmin=swap(mmin, size, q);
        sum=mmin[q][q];
    
    
        sum+=permute(mmin, q-1);
    
    
    
    
        mmin=swap(mmin, q, size);
    printf("\n");
    
    
    }
    
    
    return sum;
    }
    int swap(int mmin[10][10], int j, int k){
     int i, temp;
     for(i=0;i<=k;i++){
         printf("swapping [%d][%d]=%d with [%d][%d]=%d\n", i, j, mmin[i][j], i, k, mmin[i][k]);
         temp=mmin[i][j];
         mmin[i][j]=mmin[i][k];
         mmin[i][k]=temp;
     }
     return mmin;
    }
    I know, it's a mess. The program adds the diagonal numbers together ([0][0]+[1][1]+[2][2]+...) but the swap is giving me trouble. I only learned how to print permutations of a word, not of sums of 2D arrays. any help?
    Thanks in advance!

    I also know that i need an if statement to stop all of the swaps, but I'm not sure where yet...
    Last edited by zwolf2190; 06-15-2012 at 12:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Complex permutation of elements of an array
    By drew99 in forum C Programming
    Replies: 3
    Last Post: 10-25-2011, 12:10 PM
  2. Permutation of an array of strings
    By JonathanS in forum C Programming
    Replies: 5
    Last Post: 10-19-2011, 06:01 PM
  3. Converting character array to integer array
    By quiet_forever in forum C++ Programming
    Replies: 5
    Last Post: 04-02-2007, 05:48 AM
  4. Sorting: Getting permutation index array
    By flyvholm in forum C Programming
    Replies: 2
    Last Post: 09-20-2006, 07:07 PM
  5. INT ARRAY Permutation!
    By arthur5005 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2002, 05:30 AM

Tags for this Thread