結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 1 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;

void pvec(vector<vector<int> > &dp){
	for(int i=0; i<dp.size(); i++){
		for(int j=0; j<dp[i].size(); j++){
			cerr << dp[i][j] << " ";
			
		}
		cerr << endl;
	}
}

int dfs(vector<int> &D, vector<vector<int> > &dp, int &N, int state, int MAX_HP){
	if(dp[state][MAX_HP] >= 0) return dp[state][MAX_HP];

	
	//前の相手
	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][MAX_HP] = min( max( dp[state][MAX_HP] , tmp + D[j]), MAX_HP*100);
	}

	
	
	return dp[state][MAX_HP];

}

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