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道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...
随机推荐
- SQL Server进阶(一)T-SQL查询和编程的背景
- log4j2 的使用
log4j2 是 log4j 的升级,更为方便,更为强大. log4j2.xml 的配置以及 log4j2的依赖包使用log4j2 并没有其他的依赖包,只是在使用log4j的情况下,需要别的进行桥接 ...
- WF控制台工作流(1)
简单使用WF工作流示例: using System; using System.Linq; using System.Activities; using System.Activities.State ...
- jquery选择器最后一个,倒数第二个元素
<div> <p>1</p> <p>2</p> <p>3</p> <p>4</p> < ...
- Java读取Excel转换成JSON字符串进而转换成Java对象
Jar包
- ROS 错误之 [rospack] Error: package 'beginner_tutorials' not found
ubuntu 下面情况处理 $ cd $gedit .bashrc 再后面加入两行 source /opt/ros/indigo/setup.bash source /home/lv/catkin_w ...
- 【API】检查进程是否存在 - CreateToolhelp32Snapshot
1 学习目标 今天静态逆向mydocument病毒时,看到病毒代码为了防止自身被调试会先检测杀毒软件和调试工具的进程是否存在.如果没有杀毒软件则释放真正的病毒文件,提前熟悉一下枚举进程的反汇编代码. ...
- Visual Studio 2017中的快捷键
Ctrl+Tab: 快速切换活动文件
- C++经典面试题(最全,面中率最高)
C++经典面试题(最全,面中率最高) 1.new.delete.malloc.free关系 delete会调用对象的析构函数,和new对应free只会释放内存,new调用构造函数.malloc与fre ...
- Vue.js——component(组件)
概念: 组件(Component)是自定义元素. 作用: 可以扩展HTML元素,封装可重用的代码. <div id="myView"> <!-- 把学生的数据循环 ...