Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int a[12][12];
- vector<int>seen;
- int ans, n;
- void solve(int cur, int ind, int cost){
- if(ind == n-1){
- int x;
- x = a[cur][0];
- ans = min(ans, x+cost);
- return;
- }
- for(int i = 1; i < n; i++){
- if(seen[i] == 0){
- seen[i] = 1;
- solve(i, ind+1, cost+a[cur][i]);
- seen[i] = 0;
- }
- }
- }
- int main(){
- int t;
- cin >> t;
- while(t--){
- cin >> n;
- seen.assign(n, 0);
- for(int i= 0; i < n; i++){
- for(int j = 0; j < n; j++){
- cin >> a[i][j];
- }
- }
- ans = INT_MAX;
- solve(0, 0, 0);
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement