結果

問題 No.2955 Pizza Delivery Plan
ユーザー askr58askr58
提出日時 2024-11-08 23:14:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 5,778 ms
コンパイル使用メモリ 314,240 KB
実行使用メモリ 35,328 KB
最終ジャッジ日時 2024-11-08 23:14:32
合計ジャッジ時間 10,564 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<double> x(n+1),y(n+1);
    for(int i=0;i<n;i++){
        cin>>x[i+1]>>y[i+1];
    }
    auto dist=[&](int i,int j)->double{
        return sqrtf64((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    };  
    vector<vector<vector<double>>> dp(n+1,vector<vector<double>>(k+1,vector<double>(1<<n,-1)));

    auto rec=[&](auto rec,int v,int m,int s)->double{
        if(dp[v][m][s]!=-1)return dp[v][m][s];
        else if((s+1)==1<<n)return dp[v][m][s]=dist(v,0);
        double res=1e40;
        if(v!=0)res=rec(rec,0,k,s)+dist(v,0);
        if(m>0){
            for(int i=1;i<=n;i++){
                int u=i-1;
                if(s>>u&1)continue;
                res=min(res,rec(rec,i,m-1,s|(1<<u))+dist(v,i));
            }
        }
        return dp[v][m][s]=res;
    };
    cout<<fixed<<setprecision(10);
    cout<<rec(rec,0,k,0)<<endl;
    return 0;
}
0