Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. /*
  2. Tehnici de programare
  3.  
  4.  
  5. [1] Metoda backtracking
  6.  
  7. ================
  8.  
  9. [2] Metoda Greedy
  10. 2.1 Continium Knapsack Problem - Continium case
  11.  
  12. input.dat
  13. 5 100 numarul de obiecte greutatea + maxima a rucsacului n G
  14. 1000 120 profit + greutate p1 g1
  15. 500 20
  16. 400 200
  17. 1000 100
  18. 25 1 pn gn
  19.  
  20. de afisat
  21. 1315
  22.  
  23.  
  24. */
  25.  
  26.  
  27. #include<fstream>
  28. using namespace std;
  29. int G;
  30. int n;
  31. float O[100][3];
  32.  
  33. int read_data()
  34. {
  35.  
  36. }
  37.  
  38. int fill_data()
  39. {
  40. // aplica eficienta
  41. }
  42.  
  43. int sort_data()
  44. {
  45. // sortez dupa eficienta
  46. }
  47.  
  48. float greedy()
  49. {
  50. /*
  51. G greutatea rucsacului
  52. n numarul de obiecte
  53. O matrice cu 3 coloane ( greutate , profit , eficienta )
  54.  
  55. pseudocod
  56.  
  57. profit=0
  58. i=1 // index la obiectului curent in sirul sortat descescator dupa eficienta
  59.  
  60. atata timp cat in rucsac se mai pot depune obiecte si sirul de obiecte este neepuizat
  61. G>=0 si i<=n
  62. {
  63. daca ( G>=O[i][1] ) atunci {
  64. profit=profit+O[i][3]
  65. G=G-O[i][1]
  66. }
  67. altfel {
  68. aux=(G*100)/O[i][1]
  69. profit_aux=(O[i][3]*aux)/100;
  70. profit=profit+profit_aux;
  71. G=0;
  72. stop
  73. }
  74. i=i+1;
  75. }
  76.  
  77. intoarce profit
  78.  
  79. */
  80.  
  81. }
  82.  
  83. int main()
  84. {
  85. read_data();
  86. fill_data();
  87. sort_data();
  88. cout<<greedy(); // 1315
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement