# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
373108 | 2021-03-03T11:32:55 Z | maozkurt | Kronican (COCI16_kronican) | C++17 | 1268 ms | 4588 KB |
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> #include <string> #include <stack> #include <numeric> #include <cassert> #define endl '\n' #define sp ' ' #define pb push_back #define mp make_pair #define ff first #define ss second using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn = 25; const int inf = 1e9; int c[maxn][maxn]; int dp[1<<20]; int popcount(int n){ int ret = 0; while(n){ if(n&1) ret++; n>>=1; } return ret; } int n,k; int f(int mask){ if(dp[mask] != -1) return dp[mask]; if(popcount(mask) == k) return 0; int ret = inf; for(int i=0;i<n;i++){ if(mask & (1<<i)){ for(int j=0;j<n;j++){ if(i==j) continue; if(mask & (1<<j)){ ret = min(ret,f(mask ^ (1<<i)) + c[i][j]); } } } } return dp[mask] = ret; } int main(){ ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr); memset(dp,-1,sizeof dp); cin>>n>>k; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>c[i][j]; cout << f((1<<n)-1) << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4460 KB | Output is correct |
2 | Correct | 3 ms | 4460 KB | Output is correct |
3 | Correct | 3 ms | 4460 KB | Output is correct |
4 | Correct | 3 ms | 4460 KB | Output is correct |
5 | Correct | 12 ms | 4460 KB | Output is correct |
6 | Correct | 25 ms | 4588 KB | Output is correct |
7 | Correct | 50 ms | 4460 KB | Output is correct |
8 | Correct | 111 ms | 4496 KB | Output is correct |
9 | Correct | 1268 ms | 4460 KB | Output is correct |
10 | Correct | 222 ms | 4588 KB | Output is correct |