Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- long long int n,sum,res,a[30],x,p1w,p2w;
- void pile(long long int depth,long long int p1w,long long int p2w)
- {
- /* cout<<"suru te"<<p1w<<" "<<p2w<<endl;
- cout<<endl;
- cout<<"depth is"<<depth<<endl;
- cout<<endl;
- cout<<"n is"<<n<<endl;
- */
- if(depth>n)
- {
- // cout<<"base caser vitore"<<p1w<<" "<<p2w<<endl;
- // cout<<endl;
- res=min(res,abs(p1w-p2w));
- return;
- }
- pile(depth+1,p1w+a[depth],p2w);
- // cout<<"p1w call"<<p1w<<" "<<p2w<<endl;
- // cout<<endl;
- pile(depth+1,p1w,p2w+a[depth]);
- // cout<<"p2w call"<<p1w<<" "<<p2w<<endl;
- // cout<<endl;
- return;
- }
- int main()
- {
- long long int i;
- cin>>n;
- for(i=0; i<n; i++)
- {
- cin>>a[i];
- }
- res=10000000;
- pile(0,0,0);
- cout<<res<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement