当前位置:网站首页>AcWing 274. Mobile services [DP]
AcWing 274. Mobile services [DP]
2022-07-19 14:19:00 【Codiplay】
AcWing 274. Mobile services - AcWing
Put the stage on the outermost layer i enumeration , Don't care about the inner relationship . Because no aftereffect has been guaranteed by the outer stage .
secondly , For coordinates (x,y) still (y,x) Two for Loops can contain both , So no matter x On the outer layer or y It's the same in the outer layer , Because what you want to express is the form of coordinates , It doesn't matter who is on the outer layer , There must be .
For the first i Stage , There must be someone pi, We don't care who is pi, What I care about is except pi outside , Where are the other two positions .
So in the stage, set a two-dimensional array to record except pi Where are the other two positions .
The topological relationship between states here is quite special ,f[i][x][y] It's inconvenient to raise the dependent state , but f[i][x][y] The dependent ones are easy to enumerate
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1100;
const int M = 220;
int c[N][N];
int n, m, res = 0x3f3f3f3f;
int p[N], f[N][M][M];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n >> m;
for (int i = 1 ; i <= n; i ++ ) {
for (int j = 1; j <= n; j ++ ) {
cin >> c[i][j];
}
}
for (int i = 1; i <= m; i ++ ) {
cin >> p[i];
}
p[0] = 3;
memset(f, 0x3f, sizeof f);
f[0][1][2] = 0;
for (int i = 0; i < m; i ++ ) {
for (int x = 1; x <= n; x ++ ) {
for (int y = 1; y <= n; y ++ ) {
int z = p[i], u = f[i][x][y];
if(z == x || x == y || z == y)continue;
int v = p[i + 1];
f[i + 1][x][y] = min(f[i + 1][x][y], u + c[z][v]);//y、x You can change places
f[i + 1][z][x] = min(f[i + 1][z][x], u + c[y][v]);//z、x You can change places
f[i + 1][y][z] = min(f[i + 1][y][z], u + c[x][v]);
}
}
}
res = 0x3f3f3f3f;
for (int x = 1; x <= n; x ++ ) {
for (int y = 1; y <= n; y ++ ) {
int z = p[m];
if(z == x || x == y || y == z)continue;
res = min(res, f[m][x][y]);
}
}
cout << res << '\n';
return 0;
}边栏推荐
- STL string output and modification
- Luogu p3512 [poi2010] PIL pilots problem solution
- 4某公司在6个城市c1,c2,c3…c6中有分公司,已知城市ci到cj(I,j=1,2,3,…6)的联通情况下及费用的大小列于以下带权邻接矩阵中C中
- 面额10exp(303)的钞票
- 洛谷:P4516 [JSOI2018] 潜入行动(树形dp、树上分组背包统计方案数)
- (with source code) a variety of machine learning models (knn\lr\rf\ada\xg\gbdt...) Model training in precipitation downscaling under
- Tke mounts CFS across cloud networking
- 洛谷P2422 良好的感觉 题解
- 通达信开户是真的吗?通达信开户安全吗?
- (附源码)多种机器学习模型(KNN\LR\RF\Ada\Xg\GBDT...)下的降水降尺度中的模型训练
猜你喜欢

Notes with a face value of 10exp (303)

Silent AI: how does shengteng AI solve the problem of sign language learning with large models?

topy库的安装(拓扑优化软件)

暑期rhcsa培训第一天作业
![[7.15] code source - [neat array 2] [ternary cycle] [reverse pair on tree] [sequence of cochlea]](/img/86/8300586819e76502134e8467dc28a3.png)
[7.15] code source - [neat array 2] [ternary cycle] [reverse pair on tree] [sequence of cochlea]

Keil环境下STM32定位hardfault位置方法和遇到的情况

歐奈爾的RPS曲線的編制方法(陶博士原創)

The NFT market pattern has not changed. Can okaleido set off a new round of waves?

(附源码)多种机器学习模型(KNN\LR\RF\Ada\Xg\GBDT...)下的降水降尺度中的模型训练

FreeRTOS personal notes - multi priority support
随机推荐
A Classical Review of nonconvex optimization problems from Symmetry to Geometry, Rochester University, etc.
歐奈爾的RPS曲線的編制方法(陶博士原創)
Keil环境下STM32定位hardfault位置方法和遇到的情况
树与二分图【思维】
研二非科班研究生如何备战秋招
Unveil the mystery of service grid istio service mesh
Chrome plug-ins for information collection
How to quickly calculate the FID, is, sfid, precision, recall and other key evaluation indicators of the generated model?
Is it safe for Hongye futures to open an account online? Are there any account opening guidelines?
Uniapp Gaode map positioning function
Robotics at google:laura Graesser | i-sim2real: strengthen the learning robot strategy in the close human-computer interaction cycle
Homework for the third day of summer rhcsa training
After 2000, he was hired as a special associate researcher of Nanjing University. He went to primary school at the age of 4 and was admitted to Nanjing University at the age of 14!
【C语言】扫雷介绍与实现【数组与函数】
Go exceed API source code reading (III) -- openreader ()
Luogu p3522 [poi2011] TEM temperature solution
版本通告|Apache Doris 1.1 Release 版本正式发布!
Silent AI: how does shengteng AI solve the problem of sign language learning with large models?
Huawei wireless device configuration user CAC
No.6 representation and operation of floating point numbers