結果

問題 No.107 モンスター
ユーザー koyumeishikoyumeishi
提出日時 2014-12-19 00:51:04
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,046 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 74,592 KB
実行使用メモリ 7,724 KB
最終ジャッジ日時 2023-09-02 19:03:15
合計ジャッジ時間 7,376 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;


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;
	int ans = 0;
	ans = max( ans, dfs(D,dp,N, (1<<N)-1, max_HP) );
	cout << ans << endl;
	return 0;
}
0