An activity selection is a problem of scheduling a resource among several competing activity. The activity selection problem is also defines as : " Given a set of n activities with start time si, and fi as finish time of an ith activity. the problem is to find the maximum size set of mutually compatible activities.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
struct activity
{ int st;
int end;
} act[20];
void activity(int,int);
int ans[10];
static count=1;
void main()
{
int i,j,n;
clrscr();
cout<<"Enter the number of activities";
cin>>n;
printf<<Enter the start point and end points of the activities\n";
printf("\t START \t END");
for(i=0;i<n;i++)
scanf("%d %d",&act[i].st,&act[i].end);
activity(0,n);
cout<<"\n The set of avtivities selected are";
ans[0]=0;
count--;
for(j=0;j<=count;j++)
printf(" A%d",ans[j]+1);
getch();
}
void activity(int i,int j)
{
int m;
m=i+1;
while(m<=j && act[m].st<act[i].end)
m++;
if(m<j)
{
ans[count++]=m;
activity(m,j);
}
}
good job man
ReplyDeletethanks buddy.... if u need any kind of help with c++ then plzz let me know
ReplyDeleteneed a recursive activity selection in c
ReplyDeleteexplain when we have activity cost too
ReplyDeletecan u tell me activity selection in c++ using dynamis memory allocation
ReplyDeleteu shud indent ur code
ReplyDelete