#include<bits/stdc++.h>
using namespace std;
int job_sequence(int start[], int finish[], int profit[], int n)
{
int t[n], i, j;
t[0] = profit[0];
for(i=1;i<n;i++)
{
t[i] = max(profit[i], t[i-1]);
for(j=i-1;j>=0;j--)
{
if(finish[j] <= start[i])
{
t[i] = max(t[i], profit[i]+t[j]);
break;
}
}
}
return t[n-1];
}
int main()
{
int n, i;
cout << "Enter Job Number :: ";
cin >> n;
int start[n], finish[n], profit[n];
cout << "Enter Start and End Time and Profit :: \n";
for(i=0;i<n;i++)
{
cin >> start[i] >> finish[i] >> profit[i];
}
cout << "Maximum Profit is :: " << job_sequence(start, finish, profit, n) << "\n";
return 0;
}
using namespace std;
int job_sequence(int start[], int finish[], int profit[], int n)
{
int t[n], i, j;
t[0] = profit[0];
for(i=1;i<n;i++)
{
t[i] = max(profit[i], t[i-1]);
for(j=i-1;j>=0;j--)
{
if(finish[j] <= start[i])
{
t[i] = max(t[i], profit[i]+t[j]);
break;
}
}
}
return t[n-1];
}
int main()
{
int n, i;
cout << "Enter Job Number :: ";
cin >> n;
int start[n], finish[n], profit[n];
cout << "Enter Start and End Time and Profit :: \n";
for(i=0;i<n;i++)
{
cin >> start[i] >> finish[i] >> profit[i];
}
cout << "Maximum Profit is :: " << job_sequence(start, finish, profit, n) << "\n";
return 0;
}
Comments
Post a Comment