Codeforces 1102F Elongated Matrix 状压dp
预处理一下两两之间的最小值, 然后直接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的更多相关文章
- cf1102F. Elongated Matrix(状压dp)
题意 题目链接 Sol \(n \leqslant 16\)可以想到状压 我们可以预处理出任意两行之间每列的最小值以及相邻两列的最小值 然后枚举一个起点,\(f[sta][i]\)表示走过了\(sta ...
- codeforces Diagrams & Tableaux1 (状压DP)
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132 ...
- Codeforces 917C - Pollywog(状压 dp+矩阵优化)
UPD 2021.4.9:修了个 typo,为啥写题解老出现 typo 啊( Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1C,不过还是被我想出来了 u1 ...
- Codeforces 79D - Password(状压 dp+差分转化)
Codeforces 题目传送门 & 洛谷题目传送门 一个远古场的 *2800,在现在看来大概 *2600 左右罢( 不过我写这篇题解的原因大概是因为这题教会了我一个套路罢( 首先注意到每次翻 ...
- Codeforces 544E Remembering Strings 状压dp
题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...
- codeforces 21D. Traveling Graph 状压dp
题目链接 题目大意: 给一个无向图, n个点m条边, 每条边有权值, 问你从1出发, 每条边至少走一次, 最终回到点1. 所走的距离最短是多少. 如果这个图是一个欧拉回路, 即所有点的度数为偶数. 那 ...
- Codeforces 895C - Square Subsets 状压DP
题意: 给了n个数,要求有几个子集使子集中元素的和为一个数的平方. 题解: 因为每个数都可以分解为质数的乘积,所有的数都小于70,所以在小于70的数中一共只有19个质数.可以使用状压DP,每一位上0表 ...
- CodeForces 327E Axis Walking(状压DP+卡常技巧)
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...
- Codeforces ----- Kefa and Dishes [状压dp]
题目传送门:580D 题目大意:给你n道菜以及每道菜一个权值,k个条件,即第y道菜在第x道后马上吃有z的附加值,求从中取m道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...
随机推荐
- Java SE之字符串常量池
Reference Document: 什么是字符串常量池? http://www.importnew.com/10756.html[Recommend] Java常量池理解与总结 http: ...
- 使用Sphinx生成本地的Python帮助文档
第一步:安装Sphinx 首先我们需要安装Sphinx,如果已经安装了Anaconda,那么只需要使用如下命令即可安装,关于其中的参数 -c anaconda,可以在链接[1]中查看: conda i ...
- python 线程 event
全局定义了一个“Flag”,如果“Flag”值为 False,那么当程序执行 event.wait 方法时就会阻塞,如果“Flag”值为True,那么执行event.wait 方法时便不再阻塞. cl ...
- python Twisted安装报错
系统 mac pro 错误信息: IOError: [Errno 63] File name too long: '/var/folders/72/byjy11cs0dj_z3rjtxnj_nn000 ...
- 2018-2019-2 网络对抗技术 20165320 Exp3 免杀原理与实践
### 2018-2019-2 网络对抗技术 20165320 Exp3 免杀原理与实践 一.实验内容 1.1 正确使用msf编码器(0.5分),msfvenom生成如jar之类的其他文件(0.5分) ...
- atof()函数 atol()
atof()函数 atof():double atof(const char *str ); 功 能: 把字符串转换成浮点数 str:要转换的字符串. 返回值:每个函数返回 double 值,此值由将 ...
- makefile 中autoload
在openwrt的makefile中经常能看见这样的描述: define KernelPackage/mt7602e CATEGORY:=MTK Properties TITLE:=MTK MT7 ...
- Expm 7_1树中的最大独立集问题
[问题描述] 给定一个无回路的无向图(即树),设计一个动态规划算法,求出该图的最大独立集,并输出该集合中的各个顶点值. package org.xiu68.exp.exp7; import java. ...
- 使用swiper.js实现移动端tab切换
在项目中遇到的,要实现tab切换,我用的是swiper.js 官网:http://www.swiper.com.cn/api/start/new.html <!DOCTYPE html> ...
- SQL定义变量