首先要知道选择行列操作时顺序是无关的

用两个数组row[i],col[j]分别表示仅选择i行能得到的最大值和仅选择j列能得到的最大值

这个用优先队列维护,没选择一行(列)后将这行(列)的和减去对应的np (mp)又一次增加队列

枚举选择行的次数为i,那么选择列的次数为k - i次,ans = row[i] + col[k - i] - (k - i) * i * p;

既然顺序无关,能够看做先选择完i次行,那么每次选择一列时都要减去i * p,选择k - i次列,即减去(k - i) * i * p

//#pragma comment(linker, "/STACK:102400000,102400000")
//HEAD
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm> #include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <cstdlib> using namespace std;
//LOOP
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
//STL
#define PB push_back
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RS(s) scanf("%s", s) #define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)
#define ALL(c) (c).begin(), (c).end()
#define SZ(V) (int)V.size()
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define WI(n) printf("%d\n", n)
#define WS(s) printf("%s\n", s)
#define sqr(x) x * x typedef vector <int> VI;
typedef unsigned long long ULL;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 1010;
const double eps = 1e-10;
const LL MOD = 1e9 + 7; int ipt[maxn][maxn];
LL row[maxn * maxn], col[maxn * maxn];
LL rtol[maxn], ctol[maxn]; int main()
{
int n, m, k, p;
while (~RIV(n, m, k, p))
{
priority_queue<LL> r, c;
int radd = 0, cadd = 0;
CLR(rtol, 0), CLR(ctol, 0);
FE(i, 1, n)
FE(j, 1, m)
{
RI(ipt[i][j]);
rtol[i] += ipt[i][j];
ctol[j] += ipt[i][j];
}
FE(i, 1, n)
r.push(rtol[i]);
FE(j, 1, m)
c.push(ctol[j]);
row[0] = 0, col[0] = 0;
FE(i, 1, k)
{
LL x = r.top(), y = c.top();
r.pop(), c.pop();
r.push(x - m * p);
c.push(y - n * p);
row[i] = row[i - 1] + x;
col[i] = col[i - 1] + y;
}
// FE(i, 0, k)
// cout << row[i] + col[k - i] <<endl;
LL ans = -1e18;
FE(i, 0, k)
ans = max(ans, row[i] + col[k - i] - (LL)i * (k - i)* p);
cout << ans << endl;
}
return 0;
}
/*
2 2 4 2
1 2 3 10 2 3 5 2
2 2 2
2 2 2
*/

最新文章

  1. socket.io,命名空间
  2. $.post() 传递多个参数.
  3. xdebug影响php运行速度
  4. (转载)INSERT INTO .. ON DUPLICATE KEY 语法与实例教程
  5. grails-MappingException: Could not determine Type
  6. resin4 简单学习
  7. logstash 解析mysql slow log
  8. Pascal&#39;s Triangle II 解答
  9. JavaScript中模块“写法”
  10. windows 2008 远程端口3389修改小记
  11. poj1836--Alignment(dp,最长上升子序列变形)
  12. mysql flush操作
  13. monogodb3.4安装修改,权限设置
  14. C++中不能被重载的运算符介绍
  15. 页面布局 ——图片自动按比例显示&amp;&amp;图片随外部div的增大而按比例增大
  16. Servlet接口UML图
  17. 三.js实例
  18. 目标检测(四)Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
  19. Log4j 日志组件
  20. UIView的层次结构–code

热门文章

  1. es6--之箭头函数
  2. kali-xfce的简单配置
  3. Debian7安装msf
  4. centos 7 smplayer vlc播放器
  5. matlab中函数学习——11月14日
  6. 【JavaScript 13—应用总结】:锁屏遮罩
  7. POJ 1543 Perfect Cubes
  8. BZOJ 4810 [Ynoi2017]由乃的玉米田 ——Bitset 莫队算法
  9. HDU 3001 Travelling ——状压DP
  10. hdu 4960 记忆化搜索 DP