Advertisement
ahmad_zizo

CUT ROD

Mar 23rd, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int MAX(float arr[],int length)
  5. {
  6.     int i = 0,index=0;
  7.     float maxx = arr[0];
  8.     for(i=1 ; i<length ; i++)
  9.         if(maxx < arr[i])
  10.         {
  11.             maxx = arr[i];
  12.             index = i;
  13.         }
  14.     return index;
  15. }
  16.  
  17. int main()
  18. {
  19.     int len = 10;
  20.     int max_price = 0;
  21.     int i;
  22.     int x =0;
  23.     int length[10] = {1,2,3,4,5,6,7,8,9,10};
  24.     int pr[10] = {3,4,10,11,13,18,19,22,25,27};
  25.     float r[10];
  26.     for(i=0;i<10;i++){
  27.         r[i]= pr[i]*1.0/length[i];
  28.         //printf("%f\n",r[i]);
  29.     }
  30.     while(len){
  31.     int y = MAX(r,len);
  32.     int x= len/(y+1);
  33.     max_price = max_price + pr[y] * x;
  34.     len = len%(y+1);
  35.     }
  36.     printf("%d",max_price);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement