C.cpp 892 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[21];
  4. int used[21];
  5. int n;
  6. int tot = 0;
  7. bool flag = false;
  8. void dfs(int k) {
  9. if (flag)return;
  10. if (k == n) {
  11. int sum = 0;
  12. for (int i = 0; i < k; i++) {
  13. if (used[i])sum += a[i];
  14. }
  15. if (sum == tot)flag = true;
  16. return;
  17. }
  18. used[k] = false;
  19. dfs(k + 1);
  20. used[k] = true;
  21. dfs(k + 1);
  22. }
  23. int main() {
  24. while (cin >> n) {
  25. fill(used, used + n, false);
  26. flag = false;
  27. tot = 0;
  28. for (int i = 0; i < n; i++) {
  29. cin >> a[i];
  30. tot += a[i];
  31. }
  32. if (tot % 2 == 0) {
  33. tot /= 2;
  34. dfs(0);
  35. }
  36. if (flag)
  37. cout << "Of course,I can!" << endl;
  38. else
  39. cout << "Sorry,I can't!" << endl;
  40. }
  41. return 0;
  42. }