当前位置:网站首页>State compression DP acwing 91. shortest Hamilton path
State compression DP acwing 91. shortest Hamilton path
2022-07-27 11:18:00 【T_ Y_ F666】
State compression DP AcWing 91. The shortest Hamilton route
Original link
AcWing 91. The shortest Hamilton route
Algorithm tags
Binary status Compress DP
Ideas

Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 20, M = 1 << N;
int a[N][N], f[M][N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
rep(i, 0, n){
rep(j, 0, n){
a[i][j]=read();
}
}
memset(f, 0x3f, sizeof f);
// No journey has been made at the initial point , Therefore, the initial value bit 0
f[1][0]=0;
// i It means all the situations
rep(i, 0, 1<<n){
rep(j, 0, n){
// j Indicates which point to go
if(i>>j&1){// j Not past
// k Said go j Before this point , With k The shortest distance to the end
rep(k, 0, n){
if(i>>k&1){ //k Not past
f[i][j]=min(f[i][j], f[i-(1<<j)][k]+a[k][j]);
}
}
}
}
}
printf("%lld", f[(1<<n)-1][n-1]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- JVM judges that the object is dead, and practices verify GC recycling
- TensorFlow张量运算函数集
- Sorry, you guys have something to deal with in the bank recently, which has been delayed
- IMG SRC is empty or SRC does not exist, and the picture has a white border
- 49 letter ectopic grouping and 242 effective letter ectopic words
- Antd table+checkbox default value display
- 发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析
- Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
- Backpack model acwing 1022. Collection of pet elves
- Remember not to copy your group work, students. Fortunately, you only passed two questions. Don't have an accident
猜你喜欢

背包问题 AcWing 9. 分组背包问题

求组合数 AcWing 886. 求组合数 II

数字三角形模型 AcWing 1027. 方格取数

49字母异位分组和242有效的字母异位词

数字三角形模型 AcWing 275. 传纸条

An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft

Longest ascending subsequence model acwing 1010. Interceptor missile

A verification test of the relationship between iteration number and entropy

最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼

数字三角形模型 AcWing 1015. 摘花生
随机推荐
Cancer DDD
Today's code farmer girl learned notes about event operation and ref attribute, and did the practice of form two-way binding
泰山OFFICE技术讲座:缩放比例与打开文件
SQL Server2000数据库错误
洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
pyquery 的使用
349两个数组的交集和01两数之和
Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education
Tensorflow tensor operation function set
Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
Use of pyquery
如何创建一个带诊断工具的.NET镜像
Luogu p1441 weight weighing
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
IO stream_ Overview and explanation of data input and output flow
十年架构五年生活-07 年轻气盛的蜕变
MySQL installation (RPM package)
Learning notes - wechat payment
Error: image clipToBoundsAndScale, argument 'input'
Antd table+checkbox default value display