Codeforces Round #584 E2. Rotate Columns (hard version)
链接:
https://codeforces.com/contest/1209/problem/E2
题意:
This is a harder version of the problem. The difference is only in constraints.
You are given a rectangular n×m matrix a. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many times as you want (possibly zero). You can perform this operation to a column multiple times.
After you are done with cyclical shifts, you compute for every row the maximal value in it. Suppose that for i-th row it is equal ri. What is the maximal possible value of r1+r2+…+rn?
思路:
考虑状压DP, Dp[i][j], 表示已经对i列操作, 同时行状态为j的最大值.
枚举每列, 枚举每列的选行状态, 跟之前不冲突的状态比较.
枚举结束后转移状态,同时考虑可以选列最大值最大的n个列, 减少范围.
DP还是难啊
代码:
#include <bits/stdc++.h>
using namespace std;
int Dp[(1<<12)+10], Tmp1[(1<<12)+10], Tmp2[(1<<12)+10];
int a[20][2010], Id[2010], Val[2010];
int n, m;
bool Cmp(int l, int r)
{
if (Val[l] > Val[r])
return true;
return false;
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
memset(Val, 0, sizeof(Val));
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
{
for (int j = 1; j <= m; j++)
{
scanf("%d", &a[i][j]);
Id[j] = j;
Val[j] = max(Val[j], a[i][j]);
}
}
sort(Id + 1, Id + 1 + m, Cmp);
m = min(n, m);
memset(Dp, 0, sizeof(Dp));
for (int i = 1; i <= m; i++)
{
memcpy(Tmp2, Dp, sizeof(Dp));
memset(Tmp1, 0, sizeof(Tmp1));
for (int ti = 0; ti < n; ti++)
{
for (int s = 0; s < (1 << n); s++)
Tmp2[s] = Dp[s];
for (int s = 0; s < (1 << n); s++)
{
for (int li = 0; li < n; li++)
{
if (!((1 << li) & s))
Tmp2[s | (1 << li)] = max(Tmp2[s | (1 << li)], Tmp2[s] + a[(ti + li) % n][Id[i]]);
}
}
for (int s = 0; s < (1 << n); s++)
Tmp1[s] = max(Tmp1[s], Tmp2[s]);
}
// for (int s = 0;s < (1 << n); s++)
// cout << Tmp1[s] << ' ' ;
// cout << endl;
for (int s = 0;s < (1 << n); s++)
Dp[s] = Tmp1[s];
}
printf("%d\n", Dp[(1<<n)-1]);
}
return 0;
}
Codeforces Round #584 E2. Rotate Columns (hard version)的更多相关文章
- Codeforces Round #535 E2-Array and Segments (Hard version)
Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...
- Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树)
Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树) 题目链接 题意 给定一个nm的矩阵,每行取2k的矩阵,求总 ...
- Codeforces Round #584
传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...
- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...
- 状压DP--Rotate Columns (hard version)-- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
题意:https://codeforc.es/problemset/problem/1209/E2 给你一个n(1-12)行m(1-2000)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...
- codeforces#1290E2 - Rotate Columns (hard version)(子集dp)
题目链接: https://codeforces.com/contest/1209/problem/E2 题意: 给出$n$行和$m$列 每次操作循环挪动某列一次 可以执行无数次这样的操作 让每行最大 ...
- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version)
题目:https://codeforc.es/contest/1209/problem/G1 题意:给你一个序列,要你进行一些操作后把他变成一个好序列,好序列的定义是,两个相同的数中间的数都要与他相同 ...
- Codeforces 1209E2. Rotate Columns (hard version)
传送门 发现 $n$ 很小,考虑状压 $dp$,但是如果强行枚举列并枚举置换再转移复杂度太高了 考虑推推结论,发现我们只要保留列最大值最大的 $n$ 列即可,证明好像挺显然: 假设我们让列最大值比较小 ...
- Codeforces Round 584 题解
-- A,B 先秒切,C 是个毒瘤细节题,浪费了很多时间后终于过了. D 本来是个 sb 题,然而还是想了很久,不过幸好没什么大事. E1,看了一会就会了,然而被细节坑死,好久才过. 感觉 E2 很可 ...
随机推荐
- Openssl 加解密文件
使用openssl 的命令行进行文件的加密与解密过程,主要有两种方式: openssl 指定加密/解密算法加密 openssl 指定公钥/私钥文件加密 openssl 指定加密/解密算法加密 To E ...
- NoSQL数据库一Redis基本使用
基本操作 参考教程:https://www.yiibai.com/redis/Redis 是 Key-Value 内存数据库,操作是通过各种指令进行的,比如 SET 指令可以设置键值对,而 GET 指 ...
- GFS(Google File System,谷歌文件系统)----(1)文件系统简介
分布式文件系统 系统是构建在普通的.廉价的机器上,因此故障是常态而不是意外 系统希望存储的是大量的大型文件(单个文件size很大) 系统支持两种类型读操作:大量的顺序读取以及小规模的随机读取(larg ...
- 关联安装 mysql ,zabbix , nginx, php
/usr/local/zabbix-3.2.6 /usr/local/php-5.6.3 /usr/local/mysql-5.7.26 安装mysql mv /etc/yum.repos.d/Cen ...
- C# 重载,重写,代理,枚举实例
1.日期说法时区不同所取到的值也不同, 多个国的服务器要注意这个玩意 DateTime newDate = DateTime.Now; Console.WriteLine(newDate.ToStri ...
- hdu 2544 Dijstra模板题
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- (三)ActiveMQ之发布- 订阅消息模式实现
一.概念 发布者/订阅者模型支持向一个特定的消息主题发布消息.0或多个订阅者可能对接收来自特定消息主题的消息感兴趣.在这种模型下,发布者和订阅者彼此不知道对方.这种模式好比是匿名公告板.这种模式被概括 ...
- (六)Redis之数据结构之Set
一.常用方法 和List类型不同的是,Set集合中不允许出现重复的元素 添加/删除元素 获取集合中的元素 集合中的差集运算 集合中的交集运算 集合中的并集元算 扩展命令 1和2 添加/删除元素和获取集 ...
- Sublime Text 开发神器相关 插件安装 功能介绍
无法安装更多见http://blog.csdn.net/freshlover/article/details/44261229/ Sublime Text 3 安装插件管理 Package Contr ...
- 【原创】大叔经验分享(90)linux服务器iowait和负载很高
# top top - 21:21:51 up 207 days, 1:30, 5 users, load average: 0.90, 0.79, 1.62 Tasks: 249 total, 1 ...