답안 #884566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884566 2023-12-07T16:53:17 Z vjudge1 Kronican (COCI16_kronican) C++17
100 / 100
690 ms 4520 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int mod = 1e9 + 7;
const int maxn = 20;
const int infinito = 1e9;
int n,k;
int v[maxn][maxn];
int dp[(1<<maxn) + 10];
signed main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		for(int y = 0; y < n; y++){
			cin >> v[i][y];
		}
	}
	for(int i = 0; i <= (1<<n)-1; i++){
		dp[i] = infinito;
	}
	dp[(1<<n)-1] = 0;
	int resul = infinito;
	for(int i = (1<<n)-1; i >= 0; i--){
		int uns = __builtin_popcount(i);
		for(int y = 0; y < n; y++){
			if(((i&(1<<y)) < 1)){
				continue;
			}
			for(int j = 0; j < n; j++){
				if(j != y && ((i&(1<<j)) >= 1)){
					dp[i^(1<<y)] = min(dp[i^(1<<y)],  dp[i] + v[y][j]);
				}
			}
		}
		if(uns <= k){
			//cout << i << "  " << dp[i] << endl;
			resul = min(resul, dp[i]);
		}
		
	}
	cout << resul << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 14 ms 572 KB Output is correct
7 Correct 31 ms 2652 KB Output is correct
8 Correct 65 ms 2648 KB Output is correct
9 Correct 683 ms 4516 KB Output is correct
10 Correct 690 ms 4520 KB Output is correct