結果

問題 No.107 モンスター
コンテスト
ユーザー koyumeishi
提出日時 2014-12-19 00:51:04
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,046 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 662 ms
コンパイル使用メモリ 98,916 KB
実行使用メモリ 11,428 KB
最終ジャッジ日時 2026-03-05 05:42:58
合計ジャッジ時間 65,757 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 11 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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