题意:https://codeforc.es/problemset/problem/1209/E2

给你一个n(1-12)行m(1-2000)列的矩阵,每一列都可以上下循环移动(类似密码锁)。

问你移动后,对每一行取最大值,这些最大值再加起来的MAX是多少。

思路:

1. 首先我们有一个思维上的优化,就是我们已知n很小,m会很大。我们按照每列最大的元素值为排序标准对列进行排序。

我们发现最多只会用到前n列(就是全取每列的最大值)。

2. 枚举每列对行生效的数(就是该行这个数最大),也就是有2^n种情况,DP记录的是之前所有列对于2^n种情况的最有解,更新时对于每一种情况枚举子集并更新,

就是找新加列的互补状态的值(取max)。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int a[][];
struct node
{
int id,max_;
friend bool operator<(node a,node b)
{
return a.max_>b.max_;
}
}key[];
int dp[],DP[]; void solve()
{
int n,m;
sc("%d%d",&n,&m);
for(int i=;i<=m;++i)
key[i]={i,};
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
sc("%d",&a[i][j]),key[j].max_=max(key[j].max_,a[i][j]);
sort(key+,key++m);
m=minn(m,n);
int top=(<<n)-;
for(int i=;i<=top;++i)DP[i]=;
for(int o=;o<=m;++o)
{
for(int i=;i<=top;++i)dp[i]=;
for(int i=;i<=top;++i)
{
int sum=;
for(int pos=;pos<n;++pos)
if((i>>pos)&)
sum+=a[pos+][key[o].id];
for(int j=,now=i;j<=n;++j)
{
dp[now]=max(dp[now],sum);
if(now&)now+=<<n;
now>>=;
}
}
for(int i=top;i>=;--i)//注意要从大到小开始更新,因为大的要用到小的;
{
for(int k=i;k;k=(k-)&i)
DP[i]=max(DP[i],DP[i-k]+dp[k]);
}
}
pr("%d\n",DP[top]);
} int main()
{
// cout<<(1<<12)<<endl;
int T;
sc("%d",&T);
while(T--)solve();
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}

状压DP--Rotate Columns (hard version)-- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)的更多相关文章

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

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

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

  3. Cow and Snacks(吃点心--图论转换) Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/contest/1209/problem/D 有n个点心,有k个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会 ...

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

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;string s;pair<int,in ...

  5. 状压dp找寻环的个数 Codeforces Beta Round #11 D

    http://codeforces.com/problemset/problem/11/D 题目大意:给你n个点,m条边,找该图中有几个换 思路:定义dp[i][j]表示i是圈的集合,j表示该集合的终 ...

  6. codeforces Diagrams & Tableaux1 (状压DP)

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

  7. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  8. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  9. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

随机推荐

  1. 如何写出好的PRD(产品需求文档)(转)

    作者:Cherry,2007年进入腾讯公司,一直从事互联网广告产品管理工作,目前在SNG/效果广告平台部从事效果广告的产品运营工作. PRD(Product Requirement Document, ...

  2. LVS集群之IP TUN模式以及网站压力测试

    今天来看一下LVS的第三种模式IP TUN. TUN方式,是通过给数据包加上新的IP头部来实现,这个可以跨整个广域网. 环境: 主机名 IP 系统 角色 tiandong63 RIP:192.168. ...

  3. zstu 4237 马里奥的求救——(单调队列DP)

    题目链接:http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4237 这题可以转化为每次可以走g~d+x步,求最大分数,且最大分数的步数最少. ...

  4. [JZOJ6346]:ZYB和售货机(拓扑+基环内向森林)

    题目描述 可爱的$ZYB$来到一个售货机前. 售货机里有一共有$N(\leqslant 10^5)$个物品,每个物品有$A_i$个.自然,还有$N$个购买按钮.正常情况下,按下第$i$个按钮,需要支付 ...

  5. 4.rabbitmq--路由模式

    rabbitmq--路由模式 想象之前的订阅发布模式: 一个生产者,多个消费者,每一个消费者都有自己的一个队列,生产者没有将消息直接发送到队列,而是发送到了交换机,每个队列绑定交换机,生产者发送的消息 ...

  6. Linux 常用命令安装

    系统版本: Centos-7-x86_64-minimal 1. 网络相关 1.1 MTR 跟踪路由,还可以测试丢包率.网络延迟 yum -y  install  mtr 2. 文件相关 2.1 sz ...

  7. rabbitmq权限细分二

    禁止用户远程登录 主要有以下几步 1.进入容器 docker exec -it ID /bin/bash 2.打开配置文件 vi /etc/rabbitmq/rabbitmq.conf 3.加入配置, ...

  8. GitHub代码下载和同步

    1.下载git客户端https://git-scm.com/ssh-keygen -C "your@email.address" -t rsa 2. 把下面文件的内容复制到 htt ...

  9. lsnrctl: .... cannot restore segment prot after reloc: Permission denied

    cannot restore segment prot after reloc: Permission denied Table of Contents 1. 错误信息 2. 解决方法 1 错误信息 ...

  10. 一个Action中,可以写多个类似的业务控制方法

    1)通过模块根路径 + 功能子路径 = 访问模块下子功能的路径 @Controller @RequestMapping(value="/user") public class Us ...