Submission #725513

# Submission time Handle Problem Language Result Execution time Memory
725513 2023-04-17T14:39:36 Z vjudge1 Kronican (COCI16_kronican) C++17
100 / 100
1786 ms 8532 KB
#include <bits/stdc++.h>
using namespace std;

const int MN=21;
const int inf=1e9+7;

int n,k;
int board[MN][MN];
int dp[1<<MN];

int back(int bit){
//	cout<<bit<<endl;
	if(__builtin_popcount(bit)==k) return 0;
	if(dp[bit]>0) return dp[bit];
	
	int ans=inf;
	for(int i=1;i<=n;++i){
		if(!(bit&(1<<(i-1)))) continue;
		for(int j=1;j<=n;++j){
			if(i==j) continue;
			if(!(bit&(1<<(j-1)))) continue;
			
			ans=min(ans,board[j][i]+back(bit-(1<<(j-1))));
//			cout<<ans<<endl;
		}
	}
	return dp[bit]=ans;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			cin>>board[i][j];
		}
	}
	
	cout<<back((1<<n)-1);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 4 ms 8404 KB Output is correct
3 Correct 5 ms 8532 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 10 ms 8524 KB Output is correct
6 Correct 22 ms 8528 KB Output is correct
7 Correct 38 ms 8404 KB Output is correct
8 Correct 81 ms 8520 KB Output is correct
9 Correct 910 ms 8508 KB Output is correct
10 Correct 1786 ms 8504 KB Output is correct