G.cpp 645 B

123456789101112131415161718192021222324252627282930
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAX_N = 20;
  4. int a[MAX_N];
  5. int n, k;
  6. bool dfs(int i, int sum) {
  7. if (i == n)return sum == k;
  8. return dfs(i + 1, sum) || dfs(i + 1, sum + a[i]);
  9. }
  10. int main() {
  11. while (cin >> n) {
  12. int tot = 0;
  13. for (int i = 0; i < n; i++) {
  14. cin >> a[i];
  15. tot += a[i];
  16. }
  17. if (tot % 2 == 0) {
  18. k = tot / 2;
  19. if (dfs(0, 0))
  20. cout << "Of course,I can!" << endl;
  21. else
  22. cout << "Sorry,I can't!" << endl;
  23. } else
  24. cout << "Sorry,I can't!" << endl;
  25. }
  26. return 0;
  27. }