結果

問題 No.107 モンスター
ユーザー koyumeishikoyumeishi
提出日時 2014-12-19 01:14:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,739 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 74,836 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 22:22:46
合計ジャッジ時間 1,653 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

/*
後ろからメモ化再帰
O( (2^N)^2 * N )っぽいのでTLE
int dfs(vector<int> &D, vector<int> &dp, int &N, int state, int MAX_HP){
	if(dp[state] >= 0) return dp[state];

	
	//前の相手
	for(int j=0; j<N; j++){
		//戦っていない相手
		if( (state & (1<<j)) == 0) continue;

		//ひとつ前の状態
		int before_state = ( state & ( ~(1<<j) ) );
		
		//ひとつ前の状態の最大体力
		int before_HP = MAX_HP - (D[j]<0?1:0);
		
		if(before_HP <= 0) continue;

		int tmp = dfs(D,dp,N, before_state, before_HP);
		if(tmp <= 0) continue;
		
		dp[state] = min( max( dp[state] , tmp + D[j]), MAX_HP*100);
	}

	return dp[state];

}
*/

int main(){
	int N;
	cin >> N;
	vector<int> D(N);
	int max_HP=1;
	for(int i=0; i<N; i++){
		cin >> D[i];
		if(D[i] < 0) max_HP++;
	}
	vector<int> dp(1<<N, -1);
	dp[0] = 100;
	
	for(int i=0; i<(1<<N); i++){
		//たどり着けない状態
		if(dp[i] < 0) continue;

		//今の状態の最大体力/100
		int MAX_HP = 1;
		int tmp = i;
		for(int j=0; j<N; j++){
			//すでに戦った相手の中で悪いモンスターをカウント
			if( (i&(1<<j)) > 0 && D[j] < 0) MAX_HP++;
		}
		
		//次の相手
		for(int j=0; j<N; j++){
			//既に戦った相手
			if( (i & (1<<j)) > 0) continue;

			//次の状態
			int next_state = ( i | ( 1<<j ) );
			
			//体力が0以下になると次の状態に移れない
			if(dp[i] + D[j] <= 0) continue;
			
			dp[next_state] = max( dp[next_state], min(dp[i]+D[j], MAX_HP*100) );
		}
	}
	int ans = max(dp[(1<<N) - 1], 0);
	cout << ans << endl;
	return 0;
}
0