Submission #170503

#TimeUsernameProblemLanguageResultExecution timeMemory
170503mdn2002Kronican (COCI16_kronican)C++14
100 / 100
1374 ms8592 KiB
#include<bits/stdc++.h> using namespace std; const long long mod=998244353; int n,k,a[25][25],dp[(1<<21)]; int f(int mask,int num) { if(n-num<=k)return 0; if(dp[mask]!=-1)return dp[mask]; int mn=1e9; for(int i=0;i<n;i++) { if((mask&(1<<i))==0) { for(int j=0;j<n;j++) { if(i==j)continue; if((mask&(1<<j))==0) { mn=min(mn,a[i][j]+f((mask|(1<<i)),num+1)); } } } } return dp[mask]=mn; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("lemonade.in","r",stdin); //freopen("lemonade.out","w",stdout); memset(dp,-1,sizeof dp); cin>>n>>k; for(int i=0;i<n;i++) { for(int j=0;j<n;j++)cin>>a[i][j]; } cout<<f(0,0); }
#Verdict Execution timeMemoryGrader output
Fetching results...