Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// C++ program for activity selection problem.
- /// Prints a maximum set of activities that can be done by a single
- /// person, one at a time.
- /// Activity selection problem টা এমন আমাকে অনেক গুলা কাজ দেওয়া আছে ।
- /// start time ও end time সহ । আমি একটা সময় শুধু মাত্র একটা কাজ এই করতে পারি ।
- /// আমাকে যদি N টা কাজ দেওয়া হয় তাহলে আমি সব চেয়ে বেশী কয়টা কাজ করতে পারব ।
- /// এইখানে overlapping possible না ,মানে একটা কাজ শেষ না করে কোন কাজ শুরু করতে পারব না ।
- /// এই প্রবলেম এর solution টা অনেক সুন্দর । আমি কাজগুলাকে তাদের end time এর বেসিস এ sort করব ।
- /// এর পর আমি যে কাজটা সবার আগে আসবে তা করব । এমন এর পর এ সেই কাজটা শুরু করব যার start time
- /// এই কাজের end time এর থেকে বেশী ।
- /// are already sorted according to their finish/end time
- /// If this activity has start time greater than or
- /// equal to the finish time of previously selected
- /// activity, then select it
- /// n --> Total number of activities
- /// s[] --> An array that contains start time of all activities
- /// f[] --> An array that contains finish time of all activities
- /// যদি end time ধরে সর্ট করে , আমি সবসময় সেই সব কাজ এই নিব যাদের end time অন্য কাজগুলা থেকে আগে শেষ হচ্ছে
- /// মানে আমি best option পাচ্ছি আরো বেশী কাজ স্টার্ট করার ।
- #include <bits/stdc++.h>
- void solve(int s[], int f[], int n)
- {
- int i, j;
- printf ("Best activities: ");
- i = 0;
- std::cout<<i<<" ";
- for (j = 1; j < n; j++)
- {
- if (s[j] >= f[i])
- {
- std::cout<<j<<" ";
- i = j;
- }
- }
- std::cout<<"\n";
- }
- int main()
- {
- /// 0 1 2 3 4 5
- int s[] = {1, 3, 0, 5, 8, 5};
- int f[] = {2, 4, 6, 7, 9, 9};
- int n = sizeof(s)/sizeof(s[0]);
- std :: sort(f,f+n);
- solve(s, f, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement