Advertisement
Waliullah8328

0/1 KS

Aug 5th, 2021
1,559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int KS = 6;
  5.     int itemWeight[3] = {4,2,3};
  6.     int TotalPrice[3] = {100,75,110};
  7.    
  8.     int Profit[4][7];
  9.  
  10.     for(int i = 0; i < 4; i++)
  11.     {
  12.         for(int j = 0; j <= 6; j++)
  13.         {
  14.             Profit[i][j]=0;
  15.         }
  16.         //printf("\n");
  17.     }
  18.     for(int i = 1; i < 4; i++)
  19.     {
  20.         for(int j = 1; j <= 6; j++)
  21.         {
  22.             int curProfit =0;
  23.             if(j > itemWeight[i-1] )
  24.             {
  25.                 curProfit = TotalPrice[i-1] + Profit[i-1][j-itemWeight[i-1]];
  26.             }
  27.             if(curProfit > Profit[i-1][j])
  28.             {
  29.                 Profit[i][j] = curProfit;
  30.             }
  31.             else
  32.             {
  33.                 Profit[i][j] = Profit[i-1][j];
  34.             }
  35.         }
  36.     }
  37.    
  38.     for(int i = 0; i < 4; i++)
  39.     {
  40.         for(int j = 0; j <= 6; j++)
  41.         {
  42.             printf("%d\t",Profit[i][j]);
  43.         }
  44.         printf("\n");
  45.     }
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement