[CF1209E2]Rotate Columns (hard version)

Rotate Columns (hard version)

题解

首先,很容易发现,这n行的最大值都来自最大值最大的n列。

于是,我们可以将其变成一个n*n(或者更小)的矩形。由于n\leq 12很容易就可以想到状压dp。

f_{i,j}表示第i列总的选择行的情况为j时的最大值和,这很容易初始化出来,注意要将循环轮换后的值也更新一遍。

再定义dp_{i,j},即前i列选后,所有行选择情况为j时的最大值,这很容易用前面的f数组更新出来。

源码

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF=0x7f7f7f7f;
const LL mo=1e9+7;
typedef pair<LL,LL> pii;
int t,n,m,a[15][2005],v[2005];
int f[15][(1<<12)+5],dp[15][(1<<12)+5];
struct ming{
	int val,id;
	bool operator
posted @ 2020-08-09 16:02  StaroForgin  阅读(8)  评论(0)    收藏  举报  来源