|
|
back to boardAC For 1005,ask for quicker solution Posted by snowfly 13 Jul 2009 15:44 er......It is much easier to use violence than DP data so weak...... ----------------------------------------------------------- ask for quicker solution ----------------------------------------------------------- #include<iostream> #include<climits> using namespace std; int _ans,w[20],n; int abs(int x){ if (x<0) x=-x; return x; } void dfs_try(int depth,int a,int b){ if (depth==n){ if (abs(a-b)<_ans) _ans=abs(a-b); return ; } dfs_try(depth+1,a+w[depth],b); dfs_try(depth+1,a,b+w[depth]); } int main (void){ cin>>n; for (int i=0;i<n;++i) cin>>w[i]; _ans=INT_MAX; dfs_try(0,0,0); cout<<_ans<<endl; return 0; } |
|
|