#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int inf = 1000000009;
int map[13][13];
int cst[13];
int f[60004][13];
int dp[60004][13];
int n, m;
void init() {
int i, j;
cst[0] = 1;
for(i = 1; i <= 10; i++) cst[i] = cst[i-1]*3;
for(i = 0; i <= cst[10]; i++) {
int t = i;
for(j = 0; j < 10; j++) {
f[i][j] = t % 3;
t /= 3;
}
}
}
int main() {
int i, j, k;
init();
while( ~scanf("%d%d", &n, &m)) {
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
map[i][j] = inf;
while(m--) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
x--; y--;
map[y][x] = map[x][y] = min(map[x][y], z);
}
for(i = 0; i < cst[n]; i++)
for(j = 0; j < n; j++)
dp[i][j] = inf;
for(i &#
HDU 3001 Travelling 状态压缩DP简单题
最新推荐文章于 2019-01-08 08:29:10 发布
这篇博客介绍了一个利用状态压缩动态规划(DP)解决HDU 3001题目的方法。首先,初始化一些关键数组如cst、f、dp,然后读取地图信息并构建最小距离矩阵。接着,通过状态转移方程更新dp数组以找到最短路径。最后,输出最短路径长度,如果不存在路径则输出-1。
摘要由CSDN通过智能技术生成