Elongated Matrix

预处理一下两两之间的最小值, 然后直接dp。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e4 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m;
int Mat[][N];
int go[][];
int go2[][];
int dp[ << ][]; int main() {
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
scanf("%d", &Mat[i][j]);
int ans = ;
if(n == ) {
ans = inf;
for(int i = ; i < m - ; i++) ans = min(ans, abs(Mat[][i] - Mat[][i + ]));
printf("%d\n", ans);
return ;
}
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
if(i == j) continue;
go[i][j] = go2[i][j] = inf;
for(int k = ; k < m; k++)
go[i][j] = min(go[i][j], abs(Mat[i][k] - Mat[j][k]));
for(int k = ; k < m - ; k++) {
go2[i][j] = min(go2[i][j], abs(Mat[i][k] - Mat[j][k + ]));
}
}
}
for(int start = ; start < n; start++) {
memset(dp, -, sizeof(dp));
dp[ << start][start] = inf;
for(int S = ; S < ( << n); S++) {
for(int i = ; i < n; i++) {
if(dp[S][i] < ) continue;
for(int j = ; j < n; j++) {
if(S >> j & ) continue;
dp[S|(<<j)][j] = max(dp[S|(<<j)][j], min(go[i][j], dp[S][i]));
}
}
}
for(int i = ; i < n; i++)
ans = max(ans, min(go2[i][start], dp[(<<n)-][i]));
}
printf("%d\n", ans);
return ;
} /*
*/

Codeforces 1102F Elongated Matrix 状压dp的更多相关文章

  1. cf1102F. Elongated Matrix(状压dp)

    题意 题目链接 Sol \(n \leqslant 16\)可以想到状压 我们可以预处理出任意两行之间每列的最小值以及相邻两列的最小值 然后枚举一个起点,\(f[sta][i]\)表示走过了\(sta ...

  2. codeforces Diagrams & Tableaux1 (状压DP)

    http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...

  3. Codeforces 917C - Pollywog(状压 dp+矩阵优化)

    UPD 2021.4.9:修了个 typo,为啥写题解老出现 typo 啊( Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1C,不过还是被我想出来了 u1 ...

  4. Codeforces 79D - Password(状压 dp+差分转化)

    Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...

  5. Codeforces 544E Remembering Strings 状压dp

    题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...

  6. codeforces 21D. Traveling Graph 状压dp

    题目链接 题目大意: 给一个无向图, n个点m条边, 每条边有权值, 问你从1出发, 每条边至少走一次, 最终回到点1. 所走的距离最短是多少. 如果这个图是一个欧拉回路, 即所有点的度数为偶数. 那 ...

  7. Codeforces 895C - Square Subsets 状压DP

    题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表 ...

  8. CodeForces 327E Axis Walking(状压DP+卡常技巧)

    Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...

  9. Codeforces ----- Kefa and Dishes [状压dp]

    题目传送门:580D 题目大意:给你n道菜以及每道菜一个权值,k个条件,即第y道菜在第x道后马上吃有z的附加值,求从中取m道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...

随机推荐

  1. toFixed方法的bug

    最近在工作过程中碰到一个隐藏的bug,经调试发现竟然是toFixed函数不可靠的结果引起的.后端同学在处理价格比较的时候,用foFixed进行价格的四舍五入之后,竟然发现比较的结果有问题: 大家都知道 ...

  2. slice() 和splice()

    splice() 方法与 slice() 方法的作用是不同的,splice() 方法会直接对数组进行修改. 1, splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目. splice ...

  3. 关于django1.7.7使用ajax后出现“CSRF token missing or incorrect”问题的解决办法

    最近使用Python3.3.25和django1.7.7开发公司项目,在使用ajax来post数据时,居然一直提示:403错误,原因是“CSRF token missing or incorrect” ...

  4. CentOS挂载光盘

    mkdir /mnt/cdrom mount /dev/cdrom /mnt/cdrom umount /dev/cdrom /mnt/cdrom 在Ambari集群中配置192.168.0.210: ...

  5. Python3学习笔记10-条件控制

    Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块 var1 = 100 if var1: print("1 - if 表达式条件为 true&q ...

  6. [转]VS2015 Git 源码管理工具简单入门

    VS2015 Git 源码管理工具简单入门   1.VS Git插件 1.1 环境 VS2015+GitLab 1.2 Git操作过程图解 1.3 常见名词解释 拉取(Pull):将远程版本库合并到本 ...

  7. Tpcc-MySQL对mysql数据库进行性能测试报告、分析及使用gnuplot生成图表展示

    TPC-C是专门针对联机交易处理系统(OLTP系统)的规范,一般情况下我们也把这类系统称为业务处理系统. tpcc-mysql是percona基于TPC-C(下面简写成TPCC)衍生出来的产品,专用于 ...

  8. centos常用网络管理命令

    网卡配置命令:ifconfig (ip addr , ip link) ifconfig:显示所有活动状态的相关信息    ifconfig Interface:仅显示指定接口的相关信息    ifc ...

  9. 关于报错stale element reference: element is not attached to the page document处理

    1.现象 在执行脚本时,有时候引用一些元素对象会抛出如下异常 org.openqa.selenium.StaleElementReferenceException: stale element ref ...

  10. 基于Apache的阿里云部署Node.js服务器(Windows环境)

    1 前言 由于nodejs项目对方开放了多个端口,而且阿里云上的Apache服务器(windows)已经挂载了网站,此时需要把此项目也挂上去,网上查询资料,方法略少,基本是基于nginx版本的. 2  ...