Submission #98482

# Submission time Handle Problem Language Result Execution time Memory
98482 2019-02-23T18:41:59 Z pamaj Kronican (COCI16_kronican) C++14
90 / 100
2000 ms 8576 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
#define int long long

int n, k;
int c[maxn][maxn];
int dp[1 << 20];

int solve(const int& mask)
{
	if(__builtin_popcount(mask) >= n - k) return 0;

	if(dp[mask] != -1) return dp[mask];

	int ans = 1e9;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if(i == j or (mask & (1 << i)) or (mask & (1 << j))) continue;

			ans = min(ans, solve(mask | (1 << i)) + c[i][j]);
		}
	}

	return dp[mask] = ans;
}


int32_t main()
{
	cin >> n >> k;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
			cin >> c[i][j];
	}

	memset(dp, -1, sizeof(dp));

	cout << solve(0) << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8448 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 11 ms 8548 KB Output is correct
4 Correct 9 ms 8448 KB Output is correct
5 Correct 26 ms 8568 KB Output is correct
6 Correct 45 ms 8548 KB Output is correct
7 Correct 99 ms 8448 KB Output is correct
8 Correct 161 ms 8564 KB Output is correct
9 Execution timed out 2045 ms 8576 KB Time limit exceeded
10 Correct 215 ms 8564 KB Output is correct