Submission #165766

# Submission time Handle Problem Language Result Execution time Memory
165766 2019-11-28T14:15:48 Z asifthegreat Kronican (COCI16_kronican) C++14
100 / 100
1565 ms 12156 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 21;

int cost[N][N];
int dp[3000000];
int n,k;

bool Check(int x,int bit){return 1&(x>>bit);}
int Set(int x,int bit){return x|(1<<bit);}

int call(int mask){
	if(__builtin_popcount(mask) == n-k)return 0;
	if(dp[mask] != -1)return dp[mask];
	int &ret = dp[mask];
	ret = 1<<30;
	for(int i = 0; i < n;i++){
		if(Check(mask,i)) continue;
		for(int j = 0; j < n;j++){
			if(Check(mask,j) or i == j)continue;
			// cout << "Hell yah\n";
			ret = min(ret, call(Set(mask,j))+cost[j][i]);
		}
	}
	return ret;
}

int main()
{
	memset(dp,-1,sizeof dp);
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n ;j++){
			cin >> cost[i][j];
		}
	}
	int ans = call(0);
	cout << ans << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12024 KB Output is correct
2 Correct 12 ms 12024 KB Output is correct
3 Correct 12 ms 12024 KB Output is correct
4 Correct 13 ms 12024 KB Output is correct
5 Correct 24 ms 12024 KB Output is correct
6 Correct 40 ms 12024 KB Output is correct
7 Correct 70 ms 12024 KB Output is correct
8 Correct 149 ms 12104 KB Output is correct
9 Correct 1565 ms 12100 KB Output is correct
10 Correct 167 ms 12156 KB Output is correct