当前位置:网站首页>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;
}边栏推荐
- 华为无线设备配置动态负载均衡
- 坐标模拟矩阵旋转的公式
- Event preview | Apache Doris x Apache seatunnel joint meetup to start registration!
- 手册不全,如何手工刨出TongWeb的监控信息?
- topy库的安装(拓扑优化软件)
- NO.6浮点数的表示与运算
- Is it true that tongdaxin opens an account? Is it safe for tongdaxin to open an account?
- 洛谷:P4516 [JSOI2018] 潜入行动(树形dp、树上分组背包统计方案数)
- Some puzzles about data dictionary
- FreeRTOS implementation of idle tasks and blocking delay
猜你喜欢

No.3 advanced assembly

FreeRTOS personal notes - multi priority support
![[acwing] solution of the 60th weekly match](/img/79/5cc097c7a432e40c4bda3ef5a167de.gif)
[acwing] solution of the 60th weekly match

96. Different binary search trees

毕设-基于SSM在线预约挂号系统

Unity realizes UI backpack equipment dragging function

Introduction:Multiple DataFrames

2022年中国AI医学影像行业概览报告

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!

第二届「绿树杯」数学竞赛排名与评析
随机推荐
歐奈爾的RPS曲線的編制方法(陶博士原創)
[C language] introduction and implementation of mine sweeping [array and function]
Microservice calling component feign practice
慎用TongWeb的热部署功能
topy库的安装(拓扑优化软件)
Introduction:Multiple DataFrames
函數初認識-下
Silent AI: how does shengteng AI solve the problem of sign language learning with large models?
[7.13] code source - [hungry meals] [path count 2] [function sum]
洛谷:P3092 [USACO13NOV]No Change G(状压+二分,独特的状态定义,不写会后悔一辈子的题)
【ACWing】2521. Count colors
Huawei wireless device configuration user CAC
Redis源码与设计剖析 -- 4.跳跃表
A Classical Review of nonconvex optimization problems from Symmetry to Geometry, Rochester University, etc.
函数初认识-下
273. 分级 - AcWing题库【DP】
Run through caffe resnet-50 network to realize image classification -- Based on Huawei cloud ai1s
How to avoid global index in pychart? How to cancel the indexing of a folder?
暑期rhcsa培训第一天作业
O'Neill's RPS curve compilation method (original by Dr. Tao)