結果

問題 No.107 モンスター
ユーザー たこしたこし
提出日時 2015-01-15 22:36:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,410 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 90,568 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-04 13:16:54
合計ジャッジ時間 1,760 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000000
#define EPS 1e-9
#define Pi acos(-1)

using namespace std;

typedef long long ll;

#define MAX_N 16

int N;
int D[MAX_N];

int dp[(1 << MAX_N) + 1];

//S:倒した敵 currentLife:現在の体力
int solve(int S, int currentLife){

	if (dp[S] != -1)
		return dp[S];
	if (S == (1 << N) - 1)
		return currentLife;
	if (currentLife == 0)
		return 0;

	int maxLife = 1;

	for (int i = 0; i < N; i++){
		if (S >> i & 1 && D[i] < 0)
			maxLife++;
	}

	maxLife = maxLife * 100;

	int tmp = 0;

	for (int i = 0; i < N; i++){
		if (!(S >> i & 1)){
			//いいモンスター
			if (D[i] > 0){
				tmp = max(tmp, solve(S | 1 << i, min(maxLife, currentLife + D[i])));
			}
			//悪いモンスター
			else{
				tmp = max(tmp, solve(S | 1 << i, max(0, currentLife + D[i])));
			}
		}
	}

	return dp[S] = tmp;

}

int main(){

	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> D[i];
	}

	memset(dp, -1, sizeof(dp));

	cout << solve(0, 100) << endl;

	return 0;

}
0