Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. List<int> p = new List<int> { 1, 2, 3, 4};
  4. Console.WriteLine(F(4, 4, p));
  5. }
  6.  
  7. public static int F(int k, int n, List<int> p)
  8. {
  9. List<int> maxList = new List<int>();
  10. int ats = 0;
  11.  
  12. if (n == 0) { return 0; }
  13. else if (k == 1)
  14. {
  15. ats = 0;
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. ats += p[i];
  20. }
  21. return ats;
  22. }
  23. else
  24. {
  25. for (int i = 0; i < n; i++)
  26. {
  27. ats = 0;
  28. for (int j = i; j < n; j++)
  29. {
  30. ats += p[j];
  31. }
  32. int funkcija = F(k - 1, n - 1, p);
  33. if (ats > funkcija)
  34. {
  35. maxList.Add(ats);
  36. }
  37. else
  38. {
  39. maxList.Add(funkcija);
  40. }
  41. }
  42. }
  43. ats = maxList.Min();
  44. return ats;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement