#include<iostream>
#include<conio.h>
using namespace std;
int profit(int m[],int p[],int n)
{
    int i,j,dp[7] = {0},k,mx;
    dp[0] = p[0];                 //dp[i] = profit for opening
restaurant till i_th index which is dp[i] = max(max(dp[j])
+p[i]),p[i]) , where j<i and m[i]-m[j]>=n
    for(i=1;i<7;i++)
    {
          mx = 0;
          for(j=0;j<i;j+
+)
          {
               if((mx<dp[j])&&(m[i]-m[j]>=n))
               {
                     mx = dp[j];
                     k = j;
               }
          }
          dp[i] = max(mx+p[i],p[i]);
    }
    for(i=0;i<7;i++)
         cout<<dp[i]<<endl;
    for(i=0;i<7;i++)
         if(mx<dp[j])
                mx = dp[j];
    return mx;
}
int main()
{
    int m[7] = {1,3,5,8,9,12,15};
    int p[7] = {5,9,1,6,2,8,3};
    cout<<"\nThe maximun profit is : "<<profit(m,p,5);  // Here 5 is
the minimum distance b/w two restaurants
    getch();
}

Any suggestions ??

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to