题意:给定一个n*m的矩阵,可以在矩阵内将A个元素改成0,现在要在矩阵内选出B个不相交的宽为m的矩阵,使得这3个矩阵的和最大
这个可以将所有行压成一个点然后变成序列上的问题,修改可以预处理,显然对每行来说,应优先修改最小的元素,那么就可以预处理出a[i][j],代表第i行修改j次后的权值。显然修改的效果会越来越小,所以f(j)=a[i][j]是一个上凸函数。。
然后设d[p][i][j]为到第i行,选了p个矩形(第p个矩形以第i行结尾),修改了j次的最大值
那么d[p][i][j]=max{max{d[p][i-1][k]+a[i][j-k]},max{d[p-1][v][k]+a[i][j-k]}}
=max{max(d[p][i-1][k],d[p-1][v][k])+a[i][j-k]}
那么设g[p][i][k]=max(d[p][i][k],d[p-1][v][k])
d[p][i][j]=max{g[p][i][k]+a[i][j-k]}
复杂度是O(TnABm),显然会T
而由于a的性质比较特殊,所以这个决策具有单调性
对于2个决策点k<v<j,如果g[p][i][k]+a[i][j-k]<g[p][i][v]+a[i][j-v],由于a[i][x]为上凸函数,所以随着j增加,v一直比k优,因此可以用单调队列维护决策,用二分找到决策区间就可以了。。
Problem E. Find The Submatrix
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 43 Accepted Submission(s): 15
Problem Description
Little Q is searching for the submatrix with maximum sum in a matrix of n rows and m columns. The standard algorithm is too hard for him to understand, so he (and you) only considers those submatrixes with exactly m columns.
It is much easier now. But Little Q always thinks the answer is too small. So he decides to reset no more than A cells' value to 0, and choose no more than B disjoint submatrixes to achieve the maximum sum. Two submatrix are considered disjoint only if they do not share any common cell.
Please write a program to help Little Q find the maximum sum. Note that he can choose nothing so the answer is always non-negative.
Input
The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.
In each test case, there are 4 integers n,m,A,B(1≤n≤100,1≤m≤3000,0≤A≤10000,1≤B≤3).
Each of the following n lines contains m integers, the j-th number on the i-th of these lines is wi,j(|wi,j|≤109), denoting the value of each cell.
Output
For each test case, print a single line containing an integer, denoting the maximum sum.
Sample Input
2 5 1 0 1 3 -1 5 -1 -2 5 1 1 1 3 -1 5 -1 -2
Sample Output
7 8
Source
2018 Multi-University Training Contest 3
Recommend
chendu
Statistic | Submit | Discuss | Note