Advertisement
Guest User

xdxdxdx

a guest
Jan 23rd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. int N,K;//targyak szama, hatizsak kapacitasa
  6. int T[25],E[25];//tomegek es ertekek
  7. int H[25];// mit teszek a hatizsakba
  8. int sT[25];//a hatizsakban talalhato targyak tomege
  9. int sE[25];//a hatizsakban talalhato targyak erteke
  10. int db;
  11. int Optimalis;
  12.  
  13.  
  14. void Olvas()
  15. {
  16. ifstream f("taska.txt");
  17. f>>K;f>>N;
  18. for(int i=1;i<=N;i++)
  19. {
  20. f>>T[i]>>E[i];
  21. }
  22. f.close();
  23.  
  24. }
  25.  
  26. void Mutat()
  27. {
  28. if(sE[N]>=Optimalis)
  29. {
  30. Optimalis=sE[N];
  31.  
  32. db++;
  33. cout <<db<<"."<<endl;
  34. cout <<"Index: ";
  35. for(int i=1;i<=N;i++)
  36. {
  37. cout.width(4);
  38. cout<<i<<" ";
  39. }
  40. cout <<endl;
  41.  
  42. cout <<"Tomeg: ";
  43. for(int i=1;i<=N;i++)
  44. {
  45. cout.width(4);
  46. cout<<T[i]<<" ";
  47. }
  48. cout <<endl;
  49.  
  50. cout <<"Ertek: ";
  51. for(int i=1;i<=N;i++)
  52. {
  53. cout.width(4);
  54. cout<<E[i]<<" ";
  55. }
  56. cout <<endl;
  57.  
  58. cout <<"Zsak: ";
  59. for(int i=1;i<=N;i++)
  60. {
  61. cout.width(4);
  62. cout<<H[i]<<" ";
  63. }
  64. cout <<endl;
  65.  
  66. cout <<"Ossztomeg: "<<sT[N]<<" Osszertek: "<<sE[N]<<endl;
  67. }
  68. }
  69. int Megoldas(int k)
  70. {
  71. return(k>N);
  72. }
  73. int Jo(int k)
  74. {
  75. return(sT[k]<K);
  76. }
  77. void Back(int k)
  78. {
  79. if(Megoldas(k))
  80. Mutat();
  81. else
  82. {
  83. for(int i=0;i<=1;i++)
  84. {
  85. H[k]=i;
  86. sT[k]=sT[k-1]+T[k]*i;
  87. sE[k]=sE[k-1]+E[k]*i;
  88. if(Jo(k))
  89. Back(k+1);
  90.  
  91. }
  92.  
  93.  
  94. }
  95.  
  96.  
  97. }
  98. int main()
  99. {
  100. Olvas();
  101.  
  102. Back(1);
  103. Mutat();
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement