Pages

Wednesday, May 4, 2011

ACTIVITY SELECTION PROBLEM

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);
   }
 }

6 comments:

  1. thanks buddy.... if u need any kind of help with c++ then plzz let me know

    ReplyDelete
  2. need a recursive activity selection in c

    ReplyDelete
  3. explain when we have activity cost too

    ReplyDelete
  4. can u tell me activity selection in c++ using dynamis memory allocation

    ReplyDelete