题意

题目链接

Sol

\(n \leqslant 16\)可以想到状压

我们可以预处理出任意两行之间每列的最小值以及相邻两列的最小值

然后枚举一个起点,\(f[sta][i]\)表示走过了\(sta\)这个集合内的元素,当前在\(i\)点的\(k\)的最大值

转移的时候枚举接下来走哪个位置即可

时间复杂度\(n^3 2^n\)

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9 + 10, SS = 18;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, Lim, a[SS][MAXN], f[1 << (SS)][SS], Mn[SS][MAXN], L[SS][MAXN];
void Pre() {
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= N; j++) {
Mn[i][j] = INF; L[i][j] = INF;
for(int k = 1; k <= M; k++) chmin(Mn[i][j], (i == j) ? a[i][k] : abs(a[i][k] - a[j][k]));
for(int k = 1; k < M; k++) chmin(L[i][j], abs(a[i][k] - a[j][k + 1]));
}
}
}
int DP(int bg) {
memset(f, -1, sizeof(f));
f[1 << (bg - 1)][bg] = INF;
for(int sta = 0; sta < Lim; sta++) {
for(int i = 1; i <= N; i++) {
if(f[sta][i] == -1) continue;
for(int j = 1; j <= N; j++) {
if(sta & (1 << (j - 1))) continue;
chmax(f[sta | (1 << (j - 1))][j], min(f[sta][i], Mn[i][j]));
}
}
}
int now = 0;
for(int i = 1; i <= N; i++)
chmax(now, min(f[Lim][i], L[i][bg]));
return now;
}
int main() {
N = read(); M = read(); Lim = (1 << N) - 1;
for(int i = 1; i <= N; i++)
for(int j = 1; j <= M; j++) a[i][j] = read();
Pre();
int ans = 0;
for(int i = 1; i <= N; i++)
chmax(ans, DP(i));
cout << ans;
return 0;
}
/*
3 2
85 6
64 71
1 83 4 2
9 9
10 8
5 3
4 3
*/

cf1102F. Elongated Matrix(状压dp)的更多相关文章

  1. Codeforces 1102F Elongated Matrix 状压dp

    Elongated Matrix 预处理一下两两之间的最小值, 然后直接dp. #include<bits/stdc++.h> #define LL long long #define f ...

  2. Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)

    F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...

  3. CF1102F Elongated Matrix

    题目地址:CF1102F Elongated Matrix 没想到Div.3里还有这么好的题 其实就是求Hamilton路径 预处理 \(d\) 数组: \(d1_{i,j}\) 表示第 \(i,j\ ...

  4. CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

  5. BZOJ 4000: [TJOI2015]棋盘( 状压dp + 矩阵快速幂 )

    状压dp, 然后转移都是一样的, 矩阵乘法+快速幂就行啦. O(logN*2^(3m)) ------------------------------------------------------- ...

  6. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. BZOJ_2734_[HNOI2012]集合选数_构造+状压DP

    BZOJ_2734_[HNOI2012]集合选数_构造+状压DP 题意:<集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所有满足以 下条件的子集:若 x ...

  8. 【XSY2745】装饰地板 状压DP 特征多项式

    题目大意 你有\(s_1\)种\(1\times 2\)的地砖,\(s_2\)种\(2\times 1\)的地砖. 记铺满\(m\times n\)的地板的方案数为\(f(m,n)\). 给你\(m, ...

  9. 2018.09.28 hdu5434 Peace small elephant(状压dp+矩阵快速幂)

    传送门 看到n的范围的时候吓了一跳,然后发现可以矩阵快速幂优化. 我们用类似于状压dp的方法构造(1(1(1<<m)∗(1m)*(1m)∗(1<<m)m)m)大小的矩阵. 然后 ...

随机推荐

  1. 【ElasticSearch】:Mapping相关

    Mapping 类似数据库中的表结构定义,主要作用如下: 定义Index下的字段名(Field Name). 定义字段类型,例如数值型.字符串型.布尔型等. 定义倒排索引相关配置,比如是否索引.记录p ...

  2. POJ 2685

    #include <iostream> #include <string> #define MAXN 26 using namespace std; int _map[MAXN ...

  3. POJ 2661

    #include<iostream> #include<stdio.h> using namespace std; int main() { //freopen("a ...

  4. code=exited,status=1/failure;failed to start LSB:Bring up/down networking

    环境: CentOS 7 vmware 12 操作: 复制可使用的vmware centOS 7系统至新环境 问题: 无法启动网络 查看“systemctl status network" ...

  5. Grape简介

    什么是Grape Grape是Ruby中的一个类REST API框架,被设计用于运行在Rack上或弥补已有的web应用框架(比如Rails或者Sinatra),Grape提供了一个简单的DSL用于方便 ...

  6. Attr的visitNewClass()方法解读

    在visitNewClass()方法中有如下注释: We are seeing an anonymous class instance creation.In this case, the class ...

  7. 【工具向01】——markdown 文本编辑语言相关

    markdown简介 Markdown是一种轻量级标记语言创始人为约翰·格鲁伯.它允许人们"使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML或HTML文档".这种语言吸 ...

  8. 基于HA机制的MyCat架构——配置HAProxy

    HAProxy简介HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProxy特别适用于那些负载特大的web站点,这些站 ...

  9. 目标检测技术演进:R-CNN、Fast R-CNN、Faster R-CNN

    看到一篇循序渐进讲R-CNN.Fast R-CNN.Faster R-CNN演进的博文,写得非常好,摘入于此,方便查找和阅读. object detection,就是在给定的图片中精确找到物体所在位置 ...

  10. jemalloc总结

    jemalloc支持SMP系统和并发多线程,多线程的支持是依赖于多个'arenas',并且一个线程第一次调用内存mallocer,与其相关联的是一个特殊的arena. 线程分配arena只有三种可能的 ...