結果

問題 No.107 モンスター
ユーザー xuzijian629
提出日時 2018-11-04 19:47:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,040 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 196,800 KB
最終ジャッジ日時 2025-01-06 15:35:07
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi ds(n);
    for (int i = 0; i < n; i++) {
        cin >> ds[i];
    }

    vi dp(1 << n, -1e9);
    dp[0] = 100;
    for (int i = 1; i < 1 << n; i++) {
        int healcnt = 0;
        for (int j = 0; j < n; j++) {
            if (((i >> j) & 1) && ds[j] > 0) healcnt++;
        }
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                int k = i ^ (1 << j);
                if (ds[j] > 0) {
                    dp[i] = max(dp[i], min(i64(100) + (__builtin_popcount(i) - healcnt) * 100, dp[k] + ds[j]));
                } else {
                    i64 t = dp[k] + ds[j];
                    if (t > 0) {
                        dp[i] = max(dp[i], min(i64(100) + (__builtin_popcount(i) - healcnt) * 100, t));
                    }

                }
            }
        }
    }

    cout << (dp[(1 << n) - 1] <= 0 ? 0 : dp[(1 << n) - 1]) << endl;
}
0