# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95025 | Rouge_Hugo | Kronican (COCI16_kronican) | C++14 | 837 ms | 16036 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,k;
long long d[2000009];
long long a[22][22];
long long dp(int mask,int y)
{
if (y==k)return 0;
if(d[mask]!=-1)return d[mask];
long long mn=10000000000;
long long u=10000000000;
for(int i=0;i<n;i++)
{
int l=21;
mn=10000000000;
if (((1<<i)&mask)==(1<<i))
{
for(int j=0;j<n;j++)
{
if (i!=j&&(((1<<j)&mask)==(1<<j)))
{
mn=min(mn,a[i][j]);
}
}
u=min(u,dp(mask-(1<<i),y-1)+mn);
}
}
return d[mask]=u;
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset (d,-1,sizeof d);
cin>>n>>k;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<dp((1<<n)-1,n);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |