Advertisement
Farjana_akter

Untitled

Jun 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long int n,sum,res,a[30],x,p1w,p2w;
  4.  
  5.  
  6. void pile(long long int depth,long long int p1w,long long int p2w)
  7. {
  8. /* cout<<"suru te"<<p1w<<" "<<p2w<<endl;
  9. cout<<endl;
  10. cout<<"depth is"<<depth<<endl;
  11. cout<<endl;
  12. cout<<"n is"<<n<<endl;
  13. */
  14. if(depth>n)
  15. {
  16. // cout<<"base caser vitore"<<p1w<<" "<<p2w<<endl;
  17. // cout<<endl;
  18. res=min(res,abs(p1w-p2w));
  19. return;
  20. }
  21. pile(depth+1,p1w+a[depth],p2w);
  22. // cout<<"p1w call"<<p1w<<" "<<p2w<<endl;
  23. // cout<<endl;
  24. pile(depth+1,p1w,p2w+a[depth]);
  25. // cout<<"p2w call"<<p1w<<" "<<p2w<<endl;
  26. // cout<<endl;
  27. return;
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33. long long int i;
  34. cin>>n;
  35. for(i=0; i<n; i++)
  36. {
  37. cin>>a[i];
  38. }
  39. res=10000000;
  40. pile(0,0,0);
  41. cout<<res<<endl;
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement