Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. //--------jocul energii triunghi
  5.  
  6.  
  7. /*
  8. sepoate[j] = 1) true daca exista o submultime a multimii betelor luate in considerare pana acum
  9. cu suma lungimilor j
  10. 2) false in caz contrar
  11.  
  12. sepoate[0] = true
  13.  
  14. for(i = 1; i<=n; i++)
  15. {
  16. for(j=s2; j>=0; j--)
  17. {
  18. if(sepoate[j])
  19. sepoate[j+v[i]] = true;
  20. }
  21.  
  22. }
  23.  
  24.  
  25. */
  26.  
  27.  
  28. int main()
  29. {
  30. int v[200],sepoate[200];
  31. int i, j,s2;
  32.  
  33. int n;
  34. int suma = 0;
  35.  
  36. cin>>n;
  37. for(i = 1; i<=n; i++)
  38. {
  39.  
  40. cin>>v[i];
  41. suma+=v[i];
  42. }
  43.  
  44. s2=suma/2;
  45.  
  46. for(i = 0; i<=n; i++)
  47. sepoate[i] = false;
  48.  
  49.  
  50.  
  51. sepoate[0] = true;
  52.  
  53. for(i = 1; i<=n; i++)
  54. {
  55. for(j=s2; j>=0; j--)
  56. {
  57. if(sepoate[j])
  58. sepoate[j+v[i]] = true;
  59. }
  60.  
  61. }
  62.  
  63. j=s2;
  64. while(sepoate[j] == false)
  65. j--;
  66. cout<<j;
  67.  
  68. j++;
  69.  
  70. while(sepoate[j] == false)
  71. j++;
  72. cout<<j;
  73.  
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement