当前位置:网站首页>At5147-[agc036d]negative cycle [DP, model conversion]
At5147-[agc036d]negative cycle [DP, model conversion]
2022-07-19 11:12:00 【QuantAsk】
On the subject
Topic link :https://www.luogu.com.cn/problem/AT5147
The main idea of the topic
Yes n n n A picture of points , among i → i + 1 ( i < n ) i\rightarrow i+1(i< n) i→i+1(i<n) There is an edge with a weight of 0 0 0.
For others i , j ( i ≠ j ) i,j(i\neq j) i,j(i=j) There is an edge i → j i\rightarrow j i→j, if i < j i<j i<j So the weight is − 1 -1 −1, Otherwise 1 1 1.
Delete i → j ( i ≠ j ) i\rightarrow j(i\neq j) i→j(i=j) The price is a i , j a_{i,j} ai,j, The minimum cost is required so that there is no negative ring in the graph .
1 ≤ n ≤ 500 1\leq n\leq 500 1≤n≤500
Their thinking
This easy negative ring makes people confused and don't know how to maintain , We know that the condition for the solution of the difference constraint is that there is no negative ring , So we can consider transforming it into a differential constraint model .
Then for edges that cannot be deleted i → i + 1 i\rightarrow i+1 i→i+1 There are limits x i ≥ x i + 1 x_i\geq x_{i+1} xi≥xi+1, That is, the whole sequence is monotonous .
Then it looks like i → j ( i < j ) i\rightarrow j(i<j) i→j(i<j) Can be regarded as x i − 1 ≥ x j x_i-1\geq x_j xi−1≥xj.
Form like i ← j ( i < j ) i\leftarrow j(i<j) i←j(i<j) Can be regarded as x i ≤ x j + 1 x_i\leq x_j+1 xi≤xj+1.
That is to say x i − x j ≤ 1 x_i-x_j\leq 1 xi−xj≤1 and x i − x j ≥ 1 x_i-x_j\geq 1 xi−xj≥1 The limitation of , We consider maintaining differential arrays ( On the contrary ) y i = x i − 1 − x i y_i=x_{i-1}-x_{i} yi=xi−1−xi, Then the condition is that the sum of intervals cannot be greater than / Less than 1 1 1, Obviously, so y i y_i yi It can only be 0 / 1 0/1 0/1.
Then carefully observe this limit and you will find that there are only adjacent 1 1 1 It will work , We consider the d p dp dp To deal with it , set up f i , j , k f_{i,j,k} fi,j,k Means to achieve the second goal i i i individual , the previous 1 1 1 stay j j j It's about , One more 1 1 1 stay k k k It's about .
Prefix and a a a Array optimization can be transferred .
Time complexity : O ( n 3 ) O(n^3) O(n3)
code
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=510;
ll n,a[N][N],s[N][N],t[N][N],f[N][N],ans;
signed main()
{
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
for(ll j=1;j<=n;j++){
if(i==j)continue;
scanf("%lld",&a[i][j]);
}
for(ll i=1;i<=n;i++)
for(ll j=1;j<=i;j++)
s[i][j]=s[i][j-1]+a[j][i],
t[i][j]=t[i][j-1]+a[i][j];
memset(f,0x3f,sizeof(f));
ans=f[0][0];f[1][1]=0;
for(ll i=2;i<=n;i++){
for(ll j=1;j<i;j++)
for(ll k=1;k<=j-(j!=1);k++)
f[i][j]=min(f[i][j],f[j][k]);
for(ll j=1;j<=i;j++)
for(ll k=1;k<=j-(j!=1);k++)
f[j][k]+=s[i][i]-s[i][j-1],f[j][k]+=t[i][k-1];
}
for(ll i=1;i<=n;i++)
for(ll j=1;j<=n;j++)
ans=min(ans,f[i][j]);
printf("%lld\n",ans);
return 0;
}
边栏推荐
- Satellite network capacity improvement method based on network coding
- Modify the default path of jupyter see this article!
- Model comparison of material inventory management between sap ECC and s4hana material
- What should I do if I can't see any tiles on SAP Fiori launchpad?
- 6G smart endogenous: technical challenges, architecture and key features
- Efficient space-based computing technology for satellite communication in 6g
- Unity3d 模型中心点的转换(源代码)
- 发明闪存能赚多少钱?这是一个日本的狗血故事
- 2022/7/15
- 常用getshell工具的下载
猜你喜欢

Pytoch learning record 2 linear regression (tensor, variable)

Tire Defect Detection Using Fully Convolutional Network-论文阅读笔记

PowerCLI 脚本性能优化

OpenCV编程:OpenCV3.X训练自己的分类器

Use testeract JS offline recognition picture text record

Unity3d 读取mpu9250 例子原代码

466-82(3、146、215)

Google Earth engine - Hansen global forest change v1.8 (2000-2020) forest coverage and forest loss data set

(二)使用MySQL

37. Flex layout
随机推荐
NPC, Microsoft, etc. proposed inclusivefl: inclusive federal learning on heterogeneous devices
Unity高版本退回低版本报错问题
LeetCode 2325. Decrypt message (map)
[Huawei cloud IOT] reading notes, "Internet of things: core technology and security of the Internet of things", Chapter 3 (2)
博弈论(depu)与投资(40/100)
Huawei machine test: number of continuous licensing
leetcode-08
How to build dashboard and knowledge base in double chain note taking software? Take the embedded widget library notionpet as an example
Today's sleep quality record 79 points
早期单片机加密的一些方法 【评论区领取资料】
2022/7/15
What should I do if I can't see any tiles on SAP Fiori launchpad?
vulnhub inclusiveness: 1
(二)使用MySQL
How to change and reset forgotten root password in RHEL 9
Win10 install Apache Jena 3.17
LeetCode 2335. Minimum total time required to fill the cup
Qt 两个重载QListWidget控件对象实现selectitem drag拖拽
LeetCode 745. 前缀和后缀搜索
Pytoch learning record 2 linear regression (tensor, variable)