Advertisement
Vennox

info

Mar 10th, 2022
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int v, st, dr, valmax = 0;
  8. vector< vector<int> > valoriok;
  9.  
  10. void procesareTraseu(vector<int> traseu, int suma) {
  11.  
  12. if (suma < valmax) return;
  13. if (suma == valmax) {
  14. valoriok.push_back(traseu);
  15. }
  16. if (suma > valmax) {
  17. valmax = suma;
  18. valoriok = {};
  19. valoriok.push_back(traseu);
  20. }
  21. }
  22.  
  23. void display(vector< vector<int> > values) {
  24.  
  25. for (int i = 0; i < values.size(); i++) {
  26.  
  27. for (int u = 0; u < values[i].size(); u++) {
  28.  
  29. cout << values[i][u] << " ";
  30.  
  31. }
  32. cout << endl;
  33.  
  34. }
  35.  
  36. }
  37.  
  38. void bk(vector<int> steps, int processRow, int processCol, unsigned long int totalRows, vector<vector<int>> values) {
  39. steps.push_back(processCol);
  40.  
  41. if (processRow < totalRows) {
  42.  
  43. bk(steps, processRow + 1, processCol, totalRows, values);
  44. bk(steps, processRow + 1, processCol + 1, totalRows, values);
  45.  
  46. }
  47. else {
  48.  
  49. int s = 0;
  50. for (int i = 0; i < values.size(); i++) {
  51. s += values[i][steps[i] - 1];
  52. }
  53. procesareTraseu(steps, s);
  54. }
  55. }
  56.  
  57.  
  58. int main() {
  59.  
  60. ifstream fin("summax1.in");
  61. ofstream fout("summax1.out");
  62. unsigned long n;
  63.  
  64. fin >> v >> n >> st >> dr;
  65.  
  66. vector< vector<int> > values;
  67.  
  68. for (unsigned int i = 1; i <= n; i++) {
  69. values.push_back({});
  70. for (unsigned int u = 0; u < i; u++) {
  71. int temp;
  72. fin >> temp;
  73. values[values.size() - 1].push_back(temp);
  74. }
  75. }
  76.  
  77. bk({}, 1, 1, n, values);
  78.  
  79. //display(values);
  80.  
  81. /*for (int i = 0; i < valoriok.size(); i++) {
  82. for (int u = 0; u < valoriok[i].size(); u++) {
  83. cout << valoriok[i][u] << " ";
  84. }
  85. cout << endl;
  86. }*/
  87.  
  88. if (v == 1) fout << valoriok.size();
  89. else {
  90. for (int i = st; i <= dr; i++) {
  91. for (int u = 0; u < valoriok[i].size(); u++) {
  92. fout << valoriok[i][u] << " ";
  93. }
  94. fout << endl;
  95. }
  96. }
  97.  
  98. fin.close();
  99. fout.close();
  100.  
  101. return 0;
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement