Codeforces Round #FF (Div. 1) B. DZY Loves Modification
枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p
枚举i取最大值。。。。
2 seconds
256 megabytes
standard input
standard output
As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations.
Each modification is one of the following:
- Pick some row of the matrix and decrease each element of the row by p. This operation brings to DZY the value of pleasure equal to the sum of elements of
the row before the decreasing. - Pick some column of the matrix and decrease each element of the column by p. This operation brings to DZY the value of pleasure equal to the sum of elements
of the column before the decreasing. 
DZY wants to know: what is the largest total value of pleasure he could get after performing exactly k modifications? Please, help him to calculate this
 value.
The first line contains four space-separated integers n, m, k and p (1 ≤ n, m ≤ 103; 1 ≤ k ≤ 106; 1 ≤ p ≤ 100).
Then n lines follow. Each of them contains m integers
 representing aij (1 ≤ aij ≤ 103) —
 the elements of the current row of the matrix.
Output a single integer — the maximum possible total pleasure value DZY could get.
2 2 2 2
1 3
2 4
11
2 2 5 2
1 3
2 4
11
For the first sample test, we can modify: column 2, row 2. After that the matrix becomes:
1 1
0 0
For the second sample test, we can modify: column 2, row 2, row 1, column 1, column 2. After that the matrix becomes:
-3 -3
-2 -2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std; typedef long long int LL; const int maxn=1100; LL dpr[maxn*maxn],dpc[maxn*maxn];
LL col[maxn],row[maxn];
LL a[maxn][maxn];
priority_queue<LL> qc,qr;
int n,m,k; LL p; int main()
{
scanf("%d%d%d%I64d",&n,&m,&k,&p);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%I64d",&a[i][j]);
col[j]+=a[i][j];
row[i]+=a[i][j];
}
}
for(int i=0;i<n;i++)
qr.push(row[i]);
for(int i=0;i<m;i++)
qc.push(col[i]);
dpr[0]=dpc[0]=0;
for(int i=1;i<=k;i++)
{
LL cc=qc.top(); qc.pop();
LL rr=qr.top(); qr.pop();
dpr[i]=dpr[i-1]+rr;
dpc[i]=dpc[i-1]+cc;
qc.push(cc-p*n);
qr.push(rr-p*m);
}
LL ans=dpr[0]+dpc[k];
for(int i=1;i<=k;i++)
ans=max(ans,dpr[i]+dpc[k-i]-1LL*i*(k-i)*p);
printf("%I64d",ans);
return 0;
}
Codeforces Round #FF (Div. 1) B. DZY Loves Modification的更多相关文章
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列
		
B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...
 - Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列
		
D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...
 - Codeforces Round #FF (Div. 2)  D. DZY Loves Modification 贪心+优先队列
		
链接:http://codeforces.com/problemset/problem/447/D 题意:一个n*m的矩阵.能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行 ...
 - DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
		
题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...
 - Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
		
A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...
 - Codeforces Round #FF (Div. 2):B. DZY Loves Strings
		
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
 - Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
		
题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...
 - Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) 线段树
		
http://codeforces.com/contest/447/problem/E 题意: 给定一个数组, m次操作, 1 l r 表示区间修改, 每次 a[i] + Fibonacci[i-l ...
 - Codeforces Round #FF (Div. 2)  A. DZY Loves Hash
		
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the ...
 
随机推荐
- hdu 5001(概率DP)
			
Walk Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
 - centos7 mongodb3.4 安装
			
上传tgz 安装包 [root@localhost install_pack]# ll total 274840 -rw-r--r--. 1 root root 9393241 Jun 2 14:36 ...
 - centos使用boost过程
			
1. 安装gcc,g++,make等开发环境 yum groupinstall "Development Tools" 2. 安装boost yum install boost ...
 - list列表常用方法
			
列表是Python中常用的功能,我们知道,列表可以用来存储很多信息,掌握列表的功能有助于我们处理更多的问题,下面来看看列表都具有那些属性: 1.append(self,p_object) de ...
 - Technology share: VR is coming,are you ready?
			
►Date 2016-10-18 ►Address 上海市浦东新区严家桥1号宏慧音悦湾3号楼5楼 VR SPACE ►Events 品牌如何抢先一步,借玩VR吸引眼球,如何让客户作为VR买单? 如何结 ...
 - 十五oracle 触发器
			
一.触发器简介 触发器的定义就是说某个条件成立的时候,触发器里面所定义的语句就会被自动的执行.因此触发器不需要人为的去调用,也不能调用.然后,触发器的触发条件其实在你定义的时候就已经设定好了.这里面需 ...
 - NHibernate示例
			
1. 下载相关资源: 下载NHibernate.下载地址: http://nhforge.org/Default.aspx 下载微软Northwind示例数据库,下载地址:http://www.mic ...
 - 2017 计蒜之道 初赛 第五场  C. UCloud 的安全秘钥(中等)
			
暴力. $O(m*n)$的算法可以通过此题,每次询问$O(m)$扫$S$数组,统计不同数字的个数,每次移动最多只会变化两个数字,如果不同数字个数为$0$,那么答案加$1$. #include < ...
 - Java多线程编程——volatile关键字
			
(本篇主要内容摘自<Java多线程编程核心技术>) volatile关键字的主要作用是保证线程之间变量的可见性. package com.func; public class RunThr ...
 - Python学习之pillow库入门
			
http://python.jobbole.com/84956/ 我还是搬运工......