結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
youthfuldays072
|
| 提出日時 | 2018-10-30 04:51:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,387 bytes |
| コンパイル時間 | 916 ms |
| コンパイル使用メモリ | 91,620 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-19 10:27:36 |
| 合計ジャッジ時間 | 1,632 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | AC * 4 WA * 17 |
ソースコード
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18
int main() {
int n; cin >> n;
vector<int>d(n);
for (int i = 0; i < n; i++) {
cin >> d[i];
}
//dp[利用したモンスターの部分集合]の時に残せる体力の最大値
vector<int> dp(1 << n);
dp[0] = 100;
//部分集合sに対して全探索
for (int s = 0; s < (1 << n); s++) {
//死んでしまったら無効な値なので更新しない
if (dp[s] < 0)continue;
//最大体力は状態としてもっていないので、毎回計算して出す。
int beat = 0;
//sに含まれている要素のうち悪いモンスターの数を数える
for (int i = 0; i < n; i++) {
if (s&(1 << i) && d[i] < 0)beat++;
}
//初期体力100から現在まで倒した数*100が最大体力
int maxhp = 100 + 100 * beat;
for (int j = 0; j < n; j++) {
if ((s >> j) % 2 == 1)continue;
int nexts = s | (1 << j);
//今回利用したのが良いモンスターだった場合。
if (d[j] > 0) {
//最大体力は前回のまま。
//sからd[j]だけ回復するが、最大体力までしか回復しない。
dp [nexts] = min(maxhp, max(dp[nexts], dp[s] + d[j]));
}
//悪いモンスターと戦う場合。体力が残っている場合のみ
//+d[j]となっているがd[j]自体が負なので、hpは減っている。
else if (dp[s] + d[j] > 0) {
dp[nexts] = max(dp[nexts], dp[s] + dp[j]);
}
}
}
int all = (1 << n) - 1;
cout << max(0, dp[all]) << endl;
return 0;
}
youthfuldays072