結果

問題 No.107 モンスター
ユーザー mayoko_mayoko_
提出日時 2014-12-19 13:06:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,227 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 73,236 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 22:22:51
合計ジャッジ時間 1,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define INF 1000000000

using namespace std;
typedef long long ll;

int dp[1<<20];
int N;
int D[20];

int main(void) {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> D[i];
    }
    for (int i = 0; i < 1<<N; i++) dp[i] = -1;
    dp[0] = 100;
    for (int state = 0; state < 1<<N; state++) {
        if (dp[state] < 0) continue;
        int maxHP = 1;
        for (int i = 0; i < N; i++) {
            if (state>>i & 1) {
                if (D[i] < 0) maxHP++;
            }
        }
        maxHP *= 100;
        for (int i = 0; i < N; i++) {
            if (state>>i & 1) continue;
            if (D[i] > 0) {
                dp[state|1<<i] = max(min(dp[state] + D[i], maxHP), dp[state|1<<i]);
            } else {
                int HP = dp[state] + D[i];
                if (HP <= 0) continue;
                dp[state|1<<i] = max(dp[state] + D[i], dp[state|1<<i]);
            }
        }
    }
    cout << max(0, dp[(1<<N)-1]) << endl;
    return 0;
}
0