aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2019-07-17 14:30:33 -0400
committerGitHub2019-07-17 14:30:33 -0400
commit504851d486ba7655858936fbf6ed1ca0fffd8734 (patch)
treec936fad502744980fc1667823610a43838a4847c
parentf5f3187bdcd7b0b796ed75d418668990e79e35e7 (diff)
Create guard.cpp
-rw-r--r--2014/December/Gold/guard.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/2014/December/Gold/guard.cpp b/2014/December/Gold/guard.cpp
new file mode 100644
index 0000000..1787a44
--- /dev/null
+++ b/2014/December/Gold/guard.cpp
@@ -0,0 +1,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;
+}