SHARE
TWEET

Untitled

a guest Jul 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int const maxm = 25;
  5.  
  6. int m, d[maxm];
  7.  
  8. int main()
  9. {
  10.   scanf("%d", &m);
  11.   for(int i = 0; i < m; i++) scanf("%d", &d[i]);
  12.  
  13.   int ans = m + 1; // bound
  14.   for(int i = 0; i < (1 << m); i++) {
  15.     vector<int> pos;
  16.     pos.push_back(0);
  17.  
  18.     for(int j = 0; j < m; j++)
  19.       pos.push_back(pos.back() + ((i>>j & 1)? d[j] : -d[j]));
  20.  
  21.     sort(pos.begin(), pos.end());
  22.     ans = min(ans, (int)(unique(pos.begin(), pos.end()) - pos.begin()));
  23.   }
  24.  
  25.   printf("%d\n", ans);
  26.  
  27.   return 0;
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top