#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;#define check_i(i, node) ((1<<i) & node) //node第i位是不是有值,含第0位
#define MX 0x7f7f7f7fint n, w[11][11];
int dp[2<<10][11];int main()
{//freopen("1.txt", "r", stdin);while(scanf("%d", &n) && n){ memset(dp, 0x7f, sizeof(dp));for(int i = 0;i <= n;i++)for(int j = 0;j <= n;j++)scanf("%d", &w[i][j]);for(int i = 0;i <= n;i++)for(int j = 0;j <= n;j++)for(int k = 0;k <= n;k++)if(w[j][k] > w[j][i] + w[i][k])w[j][k] = w[j][i] + w[i][k];int mx = (1<<n+1)-1;dp[0][0] = 0;for(int i = 0; i <= n;i++){dp[(1<<i)][i] = w[0][i];}for(int i = 1; i <= mx;i++){for(int j = 0;j <= n;j++){if(check_i(j, i)){int k = (i & (~(1<<j)));if(i == (1<<j)) break;for(int z = 0;z <= n;z++){if(check_i(z, k) && dp[i][j] > dp[k][z] + w[z][j])dp[i][j] = dp[k][z] + w[z][j]; }}}}printf("%d\n", dp[mx][0]);}
}
详细解决方案
sicily 1404 第一道 状态DP
热度:40 发布时间:2023-12-21 00:03:42.0
相关解决方案
- Leetcode 1404. Number of Steps to Reduce a Number in Binary Representation to One (python)
- 1404: [蓝桥杯]2n皇后问题 Java
- 【LeetCode】1404-将二进制表示减到 1 的步骤数
- sicily 1404 第一道 状态DP
- sicily 1370 How many 0's? 递推 规律
- sicily 1192 二分匹配
- sicily 1898 2608 Tree
- sicily 1422 Table Tennis 大水
- sicily 1822 dp
- sicily 1140 国王的遗产
- sicily 1135 飞越原野
- sicily 1148 dp
- sicily 1004
- sicily 1003 水题
- sicily 1136 山海经
- sicily 1321 dijkstra
- sicily 1214 信号分析
- sicily 1142 迭代深搜
- sicily 1686
- sicily 1684
- sicily 1876 1949 不相交集+线段树
- sicily 1089 欧拉函数递推
- sicily 1802 线段树
- sicily 1800 线段树RMQ
- sicily 1303 最大权 km
- sicily 1013 poj 2195 km算法
- sicily 1419
- sicily 1221 背包
- sicily 无路可逃
- Codeforces Round 1404 简要题解