結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
kenta255
|
| 提出日時 | 2018-10-11 17:22:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,286 bytes |
| コンパイル時間 | 2,162 ms |
| コンパイル使用メモリ | 161,312 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-10-12 17:38:07 |
| 合計ジャッジ時間 | 2,959 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
vector<ll> D(n);
FOR(i,0,n)cin >> D[i];
ll dp[1<<n][n];
FOR(i,0,1<<n){
FOR(j,0,n){
dp[i][j] = -1;
}
}
FOR(i,0,n)dp[0][0]=100;
//dp[done][LEVEL] = leave HP;
FOR(i,0,(1<<n)){
FOR(j,0,n){
FOR(k,0,n){
if(dp[i][j]>0)if(!(i&(1<<k))){
if(D[k]>=0){
dp[i|1<<k][j] = max(dp[i|1<<k][j],dp[i][j]+D[k]);
if(dp[i|1<<k][j]>(j+1)*100)dp[i|1<<k][j] = (j+1)*100;
}else{
dp[i|1<<k][j+1] = max(dp[i|1<<k][j+1],dp[i][j]+D[k]);
if(dp[i|1<<k][j+1]<0)dp[i|1<<k][j+1]=-1;
}
}
}
}
}
ll ans = -1;
FOR(i,0,n)ans = max(ans,dp[(1<<n)-1][i]);
if(ans<=0){
cout << 0 << endl;
}else{
cout << ans << endl;
}
}
kenta255