Submission #98495

# Submission time Handle Problem Language Result Execution time Memory
98495 2019-02-23T19:07:09 Z thiago4532 Kronican (COCI16_kronican) C++17
100 / 100
1948 ms 16888 KB
#include <bits/stdc++.h>
// #define int int64_t
#define int uint_fast32_t
 
using namespace std;
const int maxn = 30;
int c[maxn][maxn];
int dp[1<<(maxn-9)];
int n, k;
 
int solve(int mask){
	if(n - __builtin_popcount(mask) == k) return 0;
	if(dp[mask] != -1) return dp[mask];
 
	//cout << bitset<10>(mask) << "\n";
	int ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		if(mask&(1<<(i-1))) continue;
 
		for(int j=1;j<=n;j++){
			if(i==j || mask&(1<<(j-1))) continue;
			int mask2 = mask | (1<<(i-1));
			ans = min(ans, c[i][j] + solve(mask2));
		}
	}
	return dp[mask] = ans;
}
 
int32_t main(){
	//memset(c, 0x3f3f3f3f, sizeof c);
	memset(dp, -1, sizeof dp);
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin >> c[i][j];
		}
	}
	cout << solve(0) << "\n";
	return 0;
}

Compilation message

kronican.cpp: In function 'uint_fast32_t solve(uint_fast32_t)':
kronican.cpp:13:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(dp[mask] != -1) return dp[mask];
     ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16768 KB Output is correct
2 Correct 18 ms 16768 KB Output is correct
3 Correct 16 ms 16768 KB Output is correct
4 Correct 16 ms 16772 KB Output is correct
5 Correct 26 ms 16768 KB Output is correct
6 Correct 53 ms 16768 KB Output is correct
7 Correct 76 ms 16768 KB Output is correct
8 Correct 173 ms 16788 KB Output is correct
9 Correct 1948 ms 16888 KB Output is correct
10 Correct 178 ms 16888 KB Output is correct