답안 #884545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884545 2023-12-07T16:20:08 Z tiago Kronican (COCI16_kronican) C++14
0 / 100
1341 ms 9044 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
const int maxn = 21;
const int infinito = 1e9;
int n,k;
int v[maxn][maxn];
int dp[1<<maxn];
int contaum(int g){
	int x =0;
	while(g > 0){
		x++;
		g = g - (g&(-g));
	}
	return x;
}
signed main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		for(int y = 0; y < n; y++){
			cin >> v[i][y];
		}
	}
	dp[0] = 0;
	for(int i = 1; i < (1<<n); i++){
		int uns = contaum(i);
		if(uns <= k){
			dp[i] = 0;

		}
		else{
			//cout << i << " ";
			dp[i] = infinito;
			for(int y = 0; y < n; y++){
				for(int j = 0; j < n; j++){
					if(j != y){
						//cout << y << " " << j <<  " " << (i&(1<<j)) << " " <<  (i&(1<<y)) << endl;
						if(((i&(1<<j)) >= 1) && ((i&(1<<y)) >= 1)){
							//cout << "oi" << endl;
							dp[i] = min(dp[i],  dp[i^(1<<y)] + v[y][j]);
						}
					}
				}
			}
		}
	}
	cout << dp[(1<<n) - 1] << endl;
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
2 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
3 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
4 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
5 Runtime error 11 ms 348 KB Execution failed because the return code was nonzero
6 Runtime error 27 ms 2652 KB Execution failed because the return code was nonzero
7 Runtime error 48 ms 2656 KB Execution failed because the return code was nonzero
8 Runtime error 112 ms 2648 KB Execution failed because the return code was nonzero
9 Runtime error 1341 ms 8808 KB Execution failed because the return code was nonzero
10 Runtime error 85 ms 9044 KB Execution failed because the return code was nonzero