aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2019-07-17 12:57:45 -0700
committerGitHub2019-07-17 12:57:45 -0700
commit5a4dacd66b0895b940da9f669f0c099871929e17 (patch)
tree1c1e2f4ecbffa8d2e9bb251eef9a344ef91c890a
parent6b1c4f8dd8b44b99526ac97bd5d4e9781bdf350f (diff)
Update guard.cpp
-rw-r--r--2014/December/Gold/guard.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/2014/December/Gold/guard.cpp b/2014/December/Gold/guard.cpp
index 7229505..f1c83c8 100644
--- a/2014/December/Gold/guard.cpp
+++ b/2014/December/Gold/guard.cpp
@@ -2,15 +2,16 @@
#include <iostream>
using namespace std;
-int ans = 0, h[1 << 20], DP[1 << 20] = { (int)1e9 };
+int ans = 0, 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]);
- if (h[i] >= H) ans = max(DP[i], ans);
+ int h = 0;
+ for (int j = 0; j < N; j++) i & 1 << j ? h += C[j].h : DP[i ^ 1 << j] = max(min(C[j].s, DP[i] - C[j].w), DP[i ^ 1 << j]);
+ if (h >= H) ans = max(DP[i], ans);
}
ans != 0 ? cout << ans << endl : cout << "Mark is too tall" << endl;
}