結果

問題 No.107 モンスター
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2014-11-07 21:50:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 1,598 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 88,816 KB
実行使用メモリ 8,212 KB
最終ジャッジ日時 2023-08-22 22:22:00
合計ジャッジ時間 2,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,052 KB
testcase_01 AC 4 ms
8,020 KB
testcase_02 AC 4 ms
7,964 KB
testcase_03 AC 4 ms
7,960 KB
testcase_04 AC 4 ms
7,964 KB
testcase_05 AC 4 ms
8,212 KB
testcase_06 AC 4 ms
8,024 KB
testcase_07 AC 4 ms
7,956 KB
testcase_08 AC 4 ms
8,020 KB
testcase_09 AC 4 ms
7,976 KB
testcase_10 AC 4 ms
8,016 KB
testcase_11 AC 4 ms
7,964 KB
testcase_12 AC 4 ms
8,004 KB
testcase_13 AC 21 ms
8,036 KB
testcase_14 AC 42 ms
8,012 KB
testcase_15 AC 42 ms
7,944 KB
testcase_16 AC 4 ms
8,212 KB
testcase_17 AC 11 ms
8,004 KB
testcase_18 AC 88 ms
7,960 KB
testcase_19 AC 88 ms
7,996 KB
testcase_20 AC 21 ms
7,976 KB
testcase_21 AC 21 ms
8,096 KB
testcase_22 AC 42 ms
8,104 KB
testcase_23 AC 87 ms
8,032 KB
testcase_24 AC 88 ms
7,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define MOD 1000000007

#define MAX_N 16

int d[1<<MAX_N];
int dp[MAX_N+1][1<<MAX_N];

int main(){
  int n;
  cin >> n;
  vector<int> v;
  rep(i,0,n){
    int a;
    cin>>a;
    v.pb(a);
  }
  clr(d,0);
  rep(i,0,1<<n)d[i]=100;
  rep(i,0,1<<n){
    rep(j,0,n){
      if(((i>>j)&1)==1){
        if(v[j]<0){
          d[i]+=100;
        }
      }
    }
  }
  clr(dp,0);
  dp[0][0]=100;
  rep(i,1,n+1){
    rep(j,0,1<<n){
      rep(k,0,n){
        if((j&(1<<k)) == 0 && dp[i-1][j] != 0){
          dp[i][j|(1<<k)] = max(dp[i][j|(1<<k)], min(max(dp[i-1][j]+v[k],0),d[j]));
        }
      }
    }
  }
  cout << dp[n][(1<<n)-1] << endl;
  return 0;
}

/*
シンプルなビットDPの問題を作ろうとしてできた問題。
dp[n匹目のモンスター][すでに出会ったモンスターをビットで記憶]=体力
テストケースは3時間くらい考えて作ったのでこれ以上のものは無理です。
*/
0