답안 #98468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98468 2019-02-23T18:25:59 Z pamaj Kronican (COCI16_kronican) C++14
0 / 100
41 ms 33792 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;

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

int solve(int mask, int val)
{
	if(val <= 0) return 0;

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

	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), val - 1) + c[i][j]);
		}
	}

	return dp[mask][val] = ans;
}


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

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

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if(i == 0) continue; 
			dist[i][j] = 1e9;
		}
	}
	
	memset(dp, -1, sizeof(dp));

	cout << solve(0, n - k) << "\n";

}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 41 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 33 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 37 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 38 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 36 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 38 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 34 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 38 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 41 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 36 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)