CF1310D Tourism

Make complaints:

Why this CF ... unusual, 1D 2F it should not be ... [sad]

Meaning of the questions:

Given a complete graph, the path with the time being \ (dis_ {i, j} \) is not necessarily equal to \ (dis_ {J, I} \) , number of sides \ (K \) absent odd ring and start and end points is \ (1 \) minimum path.

Due to meet the odd ring does not exist, this figure needs to be dyed black and white, then black and white side through every time, so there will be an odd ring. But enumerate this point is black or white ... complexity can go to the \ (2 ^ 2 ^ KN the n-* \) , apparently not, then you will find that in fact the most \ (k \) points need to correct stained, because your side does not exceed \ (K \) , so in theory \ (2 ^ {k} \ ) randomized suffice.

code:

#include <bits/stdc++.h>
int read() {
    int x = 0 ;
    char c = getchar() ;
    while(c < 48) c = getchar() ;
    while(c > 47) x = x * 10 + (c - 48) , c = getchar() ;
    return x ;
}

int n, k;
const int maxn = 88 ;
int dis[maxn][maxn] ;
int dp[11][maxn] ;
int main() {
    n = read() , k = read() ;
    for(int i = 1 ; i <= n ; i ++)
        for(int j = 1 ; j <= n ; j ++)
            dis[i][j] = read() ;
    int seed = 0 ;
    for(char c : "sooketxdy")
        seed = seed * 233 + c ;
    srand(seed) ;
    int times = 5000 ;
    std :: vector < int > col(n + 1 , 0);
    int ans = 1e9 ;
    while(times --) {
        for(int i = 1 ; i <= n ; i ++)
            col[i] = rand() & 1 ;
        memset(dp , 0x3f , sizeof(dp)) ;
        dp[0][1] = 0;
        for(int kk = 0 ; kk < k ; kk ++)
            for(int i = 1 ; i <= n ; i ++)
                for(int j = 1 ; j <= n ; j ++)
                    if(col[i] ^ col[j]) dp[kk + 1][j] = std :: min(dp[kk + 1][j] , dp[kk][i] + dis[i][j]) ;
        ans = std :: min(ans , dp[k][1]) ;
    }
    printf("%d" , ans) ;
    return 0 ;
}

Guess you like

Origin www.cnblogs.com/Isaunoya/p/12374606.html