結果

問題 No.107 モンスター
ユーザー tkzw_21tkzw_21
提出日時 2014-12-20 15:53:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 718 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 73,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 22:36:00
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <cstring>
#include <algorithm>

using namespace std;

int dp[1<<16+1];
vector<int> d;
int n;

int dfs(long long bit){
	int ret=-114514;
	if(dp[bit] != -1)return dp[bit];
	if((1<<n)-1 == bit)return 100;

	int cnt = 1;
	for(int i=0;i<n;i++)if(!(bit&1<<i) && d[i]<0)cnt++;

	for(int i=0;i<n;i++){
		if(!(bit&(1<<i))){
			ret = max(ret,dfs(bit|(1<<i))+d[i]);
		}
	}
	ret = min(cnt*100,ret);

	if(ret <= 0)return dp[bit] = -114514;
	return dp[bit]=ret;
}

int main(void){
	cin >> n;
	d.resize(n);
	for(int i=0;i<n;i++)
		cin >> d[i];
	memset(dp,-1,sizeof(dp));
	
	cout << max(0,dfs(0)) << endl;

	return 0;
}
0