fork download
  1. // WA ...
  2.  
  3. #include <iostream>
  4. #define endl '\n'
  5. using namespace std;
  6. const int MAX = 1200000;
  7. int n, m, x, cost = MAX + 1;
  8. int lvl[13];
  9. int t[12][13];
  10.  
  11. int check()
  12. {
  13. for (int i = 1; i < m; ++i)
  14. {
  15. if (lvl[i] < x)
  16. return 0;
  17. }
  18. return 1;
  19. }
  20.  
  21. void learn(int idx)
  22. {
  23. if (check())
  24. {
  25. if (lvl[0] < cost)
  26. cost = lvl[0];
  27. return;
  28. }
  29. if (idx == n)
  30. return;
  31. for (int i = 0; i < 2; ++i)
  32. {
  33. if (i)
  34. {
  35. for (int j = 0; j < m + 1; j++)
  36. lvl[j] += t[idx][j];
  37. learn(idx + 1);
  38. for (int j = 0; j < m + 1; j++)
  39. lvl[j] -= t[idx][j];
  40. }
  41. else
  42. learn(idx + 1);
  43. }
  44. }
  45.  
  46. int main()
  47. {
  48. ios::sync_with_stdio(false);
  49. cin.tie(NULL);
  50. cin >> n >> m >> x;
  51. for (int i = 0; i < n; i++)
  52. for (int j = 0; j < m + 1; j++)
  53. cin >> t[i][j];
  54. learn(0);
  55. if (cost > MAX)
  56. cout << -1 << endl;
  57. else
  58. cout << cost << endl;
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0s 4468KB
stdin
3 3 10
60 2 2 4
70 8 7 9
50 2 3 9
stdout
120