Guest User

Untitled

a guest
Jun 2nd, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. /*************
  2.         Author - am10
  3.              ******************/
  4. #include<bits/stdc++.h>
  5.  
  6. #define sync ios::sync_with_stdio(false)
  7. #define endl '\n'
  8. #define ll long long
  9. #define pb push_back
  10. #define pii pair <int,int>
  11.  
  12. using namespace std;
  13.  
  14. vector<pair<ll,ll> > v;
  15. ll cunt = 0;
  16. ll last;
  17. void fund(ll start, ll end)
  18. {
  19.     if(start == last)
  20.     {
  21.       cunt++;
  22.       if(cunt > 1000000007)
  23.         cunt = cunt%100000000;
  24.       return;
  25.     }
  26.     // If start time of activity is less than present activity end time so don't select it
  27.     if(v[start].first < end)
  28.        fund(start+1,end);
  29.     else
  30.     {
  31.       //select present activity change end to end time of present activity
  32.       fund(start+1,v[start].second);
  33.        //don't select present activity so end will not change
  34.       fund(start+1,end);
  35.     }
  36.    
  37. }
  38.  
  39. int main()
  40. {
  41.   sync;
  42.   while(1)
  43.   {
  44.     ll n;
  45.     cin >> n;
  46.     last = n;
  47.     if(n == -1)
  48.       break;
  49.     for(int i=0;i<n;i++)
  50.     {
  51.       ll a,b;
  52.       cin >> a >> b;
  53.       v.pb({a,b});
  54.     }
  55.     sort(v.begin(),v.end());
  56.     //This is recursive function to calculate result i.e total activies
  57.     fund(0,-1);
  58.     ll res = cunt - 1;
  59.     int tot = 0;
  60.     while(res!=0)
  61.     {
  62.       res=res/10;
  63.       tot++;
  64.     }
  65.     for(int i=0;i<8-tot;i++)
  66.       cout << "0";
  67.     // subtracting -1 as there will be case when none of the activities is selected
  68.     cout << cunt-1 << endl;
  69.     v.clear();
  70.     cunt = 0;
  71.   }
  72. }
Add Comment
Please, Sign In to add comment