usaco

Clean implementations of solutions to USACO problems

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
#include <algorithm>
#include <iostream>
using namespace std;

int h[1 << 20], DP[1 << 20] = { (int)1e9 };

struct cow { int h, w, s; } C[20];

int main() {
	int N, H;
	cin >> N >> H;
	for (int i = 0; i < N; i++) cin >> C[i].h >> C[i].w >> C[i].s;

	for (int i = 0; i < (1 << N); i++) {
		for (int j = 0; j < N; j++) i & 1 << j ? h[i] += C[j].h : DP[i ^ 1 << j] = max(min(C[j].s, DP[i] - C[j].w), DP[i ^ 1 << j]);
	}

	int ans = 0;
	for (int i = 0; i < (1 << N); i++) if (h[i] >= H) ans = max(DP[i], ans);
	ans != 0 ? cout << ans << endl : cout << "Mark is too tall" << endl;
}