版本比较
状压Dp
正文
增加 2 行删除 2 行
47 行未改动4849505152525354555638 行未改动95969798999910010110210312 行未改动47 行未改动 if((i>>(j-1))&1){ for(int k = 1;k<=n;k++){ dp[i][j] = min(dp[i][j],dp[i^(1<<(j-1))][k]+w[k][j]); } } } } } int i = (1<<n)-1,j = 1; for(int k = 1;k<=n;k++){38 行未改动 for(int q = 0;q<(1<<n);q++){ if((j&(q<<1)) == 0 && (j&(q>>1)) == 0 && (j&q) == 0 && (j&(j<<1)) == 0 && (j&(j>>1)) == 0){ dp[i][j][k1] = dp[i][j][k1]+dp[i-1][q][k1-s1[j]]; } } } } } } long long ans = 0;12 行未改动