链接:

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)的更多相关文章

  1. Codeforces Round #535 E2-Array and Segments (Hard version)

    Codeforces Round #535 E2-Array and Segments (Hard version) 题意: 给你一个数列和一些区间,让你选择一些区间(选择的区间中的数都减一), 求最 ...

  2. Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树)

    Codeforces Round #620 F2. Animal Observation (hard version) (dp + 线段树) 题目链接 题意 给定一个nm的矩阵,每行取2k的矩阵,求总 ...

  3. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  4. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  5. 状压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)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...

  6. codeforces#1290E2 - Rotate Columns (hard version)(子集dp)

    题目链接: https://codeforces.com/contest/1209/problem/E2 题意: 给出$n$行和$m$列 每次操作循环挪动某列一次 可以执行无数次这样的操作 让每行最大 ...

  7. 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 题意:给你一个序列,要你进行一些操作后把他变成一个好序列,好序列的定义是,两个相同的数中间的数都要与他相同 ...

  8. Codeforces 1209E2. Rotate Columns (hard version)

    传送门 发现 $n$ 很小,考虑状压 $dp$,但是如果强行枚举列并枚举置换再转移复杂度太高了 考虑推推结论,发现我们只要保留列最大值最大的 $n$ 列即可,证明好像挺显然: 假设我们让列最大值比较小 ...

  9. Codeforces Round 584 题解

    -- A,B 先秒切,C 是个毒瘤细节题,浪费了很多时间后终于过了. D 本来是个 sb 题,然而还是想了很久,不过幸好没什么大事. E1,看了一会就会了,然而被细节坑死,好久才过. 感觉 E2 很可 ...

随机推荐

  1. vue-cli webpack打包后加载资源的路径问题

    vue项目,访问打包后的项目,输入路径后,页面加载空白.这时会有两类问题,都是路径问题. 1.一个是css,js,ico等文件加载不到,是目录里少了dist 打开页面时一片空白 解决办法: confi ...

  2. Error Retries and Exponential Backoff in AWS

    Error Retries and Exponential Backoff in AWS https://docs.aws.amazon.com/general/latest/gr/api-retri ...

  3. vmstat命令详解--转载

    一.前言 vmstat命令:  用来获得有关进程.虚存.页面交换空间及 CPU活动的信息.这些信息反映了系统的负载情况 二.虚拟内存运行原理 在系统中运行的每个进程都需要使用到内存,但不是每个进程都需 ...

  4. go 函数定义

    -------------------------------------------- package main import "fmt" func add(x int, y i ...

  5. Error:Could not find method google() for arguments [] on repository container

    Error:Could not find method google() for arguments [] on repository container. Consult IDE log for m ...

  6. Vue解决项目白屏

    第一步:  vue-cli项目根目录下面新建Vue.config.js文件  proxy反向代理    module.exports = {   devServer: {     proxy: {   ...

  7. SSH框架结合案例构建配置

    ssh框架概述 SSH是 struts+spring+hibernate的一个集成框架,是目前比较流行的一种Web应用程序开源框架.区别于 Secure Shell . 集成SSH框架的系统从职责上分 ...

  8. Sonya and Bitwise OR CodeForces - 1004F (线段树,分治)

    大意: 给定序列$a$, 给定整数$x$. 两种操作(1)单点修改 (2)给定区间$[l,r]$,求有多少子区间满足位或和不少于$x$. 假设不带修改. 固定右端点, 合法区间关于左端点单调的. 可以 ...

  9. datagrid使用和文字超出tip提示

    function LoadTable(queryData) {             $("#eventInfoTable").datagrid({               ...

  10. 通过Kubeadm搭建Kubernetes集群

    历经断断续续学习的两天,终于完成了一个简单k8s集群. 参考 https://www.cnblogs.com/edisonchou/p/aspnet_core_on_k8s_deepstudy_par ...