結果

問題 No.107 モンスター
ユーザー 小指が強い人小指が強い人
提出日時 2016-06-25 01:42:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,176 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 77,868 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2023-08-02 02:04:49
合計ジャッジ時間 7,641 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,388 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 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 <algorithm>
#include <utility>
#include <math.h>
using namespace std;

typedef pair<int,int> pai;

int n,maxn;
int d[16];
vector<pai> dp[16];

pai solve(int i,int bit){
    if(bit==maxn){
        if(d[i]>0)
            return pai(100,0);
        else
            return pai(max(0,100+d[i]),1);
    }
    if(dp[i][bit].first>0)return dp[i][bit];
    pai res(0,0);
    for(int x=0;x<n;x++){
        int mask=1<<x;
        if((bit&mask)>0)continue;
        pai t=solve(x,bit|mask);
        if(t.first<=0)continue;
        if(d[i]<0){
            t.first+=d[i];
            t.second++;
            if(t.first>0)
                res=max(t,res);
        }
        else{
            t.first=min(t.first+d[i],(t.second+1)*100);
            res=max(t,res);
        }
    }
    return dp[i][bit]=res;
}

int main(){
    cin>>n;
    maxn=pow(2,n)-1;
    for(int i=0;i<n;i++)cin>>d[i];
    for(int i=0;i<n;i++){
        dp[i].resize(1<<n);
        for(int j=0;j<n;j++){
            dp[i][j].second=dp[i][j].first=0;
        }
    }
    int res=0;
    for(int i=0;i<n;i++)res=max(res,solve(i,1<<i).first);
    cout<<res<<endl;
    return 0;
}
0