aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2019-07-17 12:52:49 -0700
committerGitHub2019-07-17 12:52:49 -0700
commit6b1c4f8dd8b44b99526ac97bd5d4e9781bdf350f (patch)
tree83e38c42fc02ef94d19187481db73d869f37e87b
parentea1cdbe03713b8ab658c2273ebeb47b07c36487e (diff)
Update guard.cpp
-rw-r--r--2014/December/Gold/guard.cpp8
1 files changed, 2 insertions, 6 deletions
diff --git a/2014/December/Gold/guard.cpp b/2014/December/Gold/guard.cpp
index 351783a..7229505 100644
--- a/2014/December/Gold/guard.cpp
+++ b/2014/December/Gold/guard.cpp
@@ -2,19 +2,15 @@
#include <iostream>
using namespace std;
-int h[1 << 20], DP[1 << 20] = { (int)1e9 };
-
+int ans = 0, 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]);
+ if (h[i] >= H) ans = max(DP[i], ans);
}
-
- 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;
}