結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
kosakkun
|
| 提出日時 | 2017-01-11 12:26:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 1,499 bytes |
| コンパイル時間 | 1,042 ms |
| コンパイル使用メモリ | 95,264 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-21 07:34:33 |
| 合計ジャッジ時間 | 2,374 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;
int dp[1<<16];
int main(){
int N; cin>>N;
vector<int> D(N);
REP(i,N)cin>>D[i];
REP(i,1<<16)dp[i]=-1e9;
dp[0] = 100;
for (int i=0; i<(1<<N); i++ ) {
for (int j=0; j<N; j++ ) {
int mask = (1<<j);
if( i&mask ) {
if( dp[i^mask]+D[j] >0 ) {
dp[i] = max(dp[i],dp[i^mask]+D[j]);
}
}
}
int cnt=1;
for (int j=0; j<N; j++ ){
if ( (i>>j)&1 ) {
if( D[j]<0 ) cnt++;
}
}
dp[i] = min(dp[i],cnt*100);
}
if(dp[(1<<N)-1]<=0)cout<<0<<endl;
else cout<<dp[(1<<N)-1]<<endl;
return 0;
}
kosakkun