結果
問題 | No.107 モンスター |
ユーザー |
![]() |
提出日時 | 2018-03-06 14:02:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 14 ms / 5,000 ms |
コード長 | 1,231 bytes |
コンパイル時間 | 599 ms |
コンパイル使用メモリ | 72,436 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-18 18:42:48 |
合計ジャッジ時間 | 1,798 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; typedef long long i64; typedef long double ld; typedef pair<i64,i64> P; #define rep(i,s,e) for(int i = (s);i <= (e);i++) int n; int d[16]; int dp[(1 << 16)]; int main() { cin >> n; rep(i,0,n - 1) cin >> d[i]; fill(dp , dp + (1 << 16),-1e9); dp[0] = 100; rep(i,1,(1 << n) - 1) { rep(j,0,n - 1) { if(i & (1 << j)) { //now take [j] int sub = i & ~(1 << j); //already die? if(dp[sub] <= 0) continue; int maxHP = 100; rep(k,0,n - 1) { if(sub & (1 << k) && d[k] < 0) maxHP += 100; } if(d[j] > 0) { dp[i] = max(dp[i] , min(dp[sub] + d[j] , maxHP)); } else { dp[i] = max(dp[i], dp[sub] + d[j]); } } } } if(dp[(1 << n) - 1] <= 0) dp[(1 << n) - 1] = 0; cout << dp[(1 << n) - 1] << endl; }