long long findMaxProfit(Job Jobs[], long long n)
{
    // Sort Jobs according to finish time

    qsort(Jobs,n,sizeof(Job),cmpfunc);

    long long table[100000 + 10];
    table[0] = 1;



    int i;

    for (i=1; i < n; i++)
    {

        int inclProf = 1;
        int l = latestNonConflict(Jobs, i);
        if (l != -1)
            inclProf += table[l];


        if(inclProf > table[i-1])
            table[i] = inclProf;
        else
            table[i] = table[i-1];
    }


    long long result = table[n-1];

    return result;
}
예제 #2
0
//O(n^2)
int findMaxProfit(Job arr[], int n) {
    // Sort jobs according to finish time
    sort(arr, arr+n, myfunction);
 
    // Create an array to store solutions of subproblems.  table[i]
    // stores the profit for jobs till arr[i] (including arr[i])
    int *table = new int[n];
    table[0] = arr[0].profit;
 
    // Fill entries in M[] using recursive property
    for (int i=1; i<n; i++) {
        // Find profit including the current job
        int inclProf = arr[i].profit;
        int l = latestNonConflict(arr, i);
        if (l != -1)
            inclProf += table[l];
 
        // Store maximum of including and excluding
        table[i] = max(inclProf, table[i-1]);
    }
 
    int result = table[n-1];
    delete[] table;
 
    return result;
}