# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101121 | InvMOD | Kronican (COCI16_kronican) | C++14 | 616 ms | 4432 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define siz(v) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}
const int N = 20;
const int inf = 2e6+1;
int n, k, C[N][N];
int dp[(1<<N)];
void solve()
{
cin >> n >> k;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> C[i][j];
}
}
dp[0] = 0;
int answer = inf;
fill(dp+1, dp+(1<<n), inf);
for(int mask = 0; mask < (1<<n); mask++){
if(__builtin_popcount(mask) >= n-k){
answer = min(answer, dp[mask]);
}
else{
for(int i = 0; i < n; i++){
if(!(mask>>i&1)){
for(int j = 0; j < n; j++){
if(i != j && !(mask>>j&1)){
dp[mask^(1<<i)] = min(dp[mask^(1<<i)], dp[mask] + C[i][j]);
}
}
}
}
}
}
cout << answer <<"\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |