Codeforces Round #FF (Div. 2) D. DZY Loves Modification 贪心+优先队列
链接:http://codeforces.com/problemset/problem/447/D
题意:一个n*m的矩阵。能够进行k次操作,每次操作室对某一行或某一列的的数都减p,获得的得分是这一行或列原来的数字之和。求N次操作之后得到的最高得分是多少。
思路:首先分别统计每行和每列的数字和。
进行的k次操作中,有i次操作是对行进行操作,剩余k-i次操作是对列进行操作。
首先在操作中忽略每次操作中行对列的影响,然后计算列的时候,最后能够计算出,总共的影响是i*(k-i)*p。
找出对于每一个i次操作选取最高价值来计算出得到的最高分。记录为cn[i],rn[i](用优先队列取首)。
对于不同的i取ans=max(cn[i]+rn[k-i]-i*(k-i)*p)。
注意点是数据会超int,ans初始值要取得极小。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<ctype.h>
#include<cstdlib>
#include<algorithm>
#include<string>
#define PI acos(-1.0)
#define maxn
typedef long long ll;
using namespace std;
long long INF =(1LL << 60);
priority_queue < long long > c,r;
int main()
{
int n,m,k,p,x;
long long y;
scanf("%d%d%d%d",&n,&m,&k,&p);
int col[1005],row[1005];
long long cn[1000005],rn[1000005];
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
scanf("%d",&x);
col[j]+=x;
row[i]+=x;
}
for(int i=0; i<n; i++)
r.push(row[i]);
for(int i=0; i<m; i++)
c.push(col[i]);
cn[0]=rn[0]=0;
for(int i=1; i<=k; i++)
{
y=c.top();
cn[i]=cn[i-1]+y;
c.pop();
c.push(y-n*1LL*p);
y=r.top();
rn[i]=rn[i-1]+y;
r.pop();
r.push(y-m*1LL*p);
}
long long ans=-INF;
for(int i=0; i<=k; i++)
ans=max(ans,cn[i]+rn[k-i]-i*1LL*(k-i)*p);
printf("%I64d\n",ans);
return 0;
}
Codeforces Round #FF (Div. 2) D. 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. 1) B. DZY Loves Modification
枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...
- 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 ...
随机推荐
- 0420-mysql命令(数据库操作层级,建表,对表的操作)
注意事项: 符号必须为英文. 数据库操作层级: 建表大全: #新建表zuoye1:drop table if exists zuoye1;create table zuoye1( id int ...
- 原生JS---1
js的历史 在上个世纪的1995年,当时的网景公司正凭借其Navigator浏览器成为Web时代开启时最著名的第一代互联网公司. 由于网景公司希望能在静态HTML页面上添加一些动态效果,于是叫Bren ...
- selenium3 + python - js处理readonly属性
前言 日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如何解决日历控件为readonly属性的问题. 基本思路:先用j ...
- java 关键字与保留字
Java 关键字列表 (依字母排序 共51组),所有的关键字都是小写,在MyEclipse中都会显示不同的颜色: abstract, assert,boolean, break, byte, case ...
- bootstrap 网格布局
一:基本的网格布局 <div class="container"> <div class="row"> <div class=&q ...
- Android 复制文本内容到系统剪贴板(自由复制)
直接上代码:(对应的类:android.content.ClipboardManager) //获取剪贴板管理器: ClipboardManager cm = (ClipboardManager) g ...
- Windows-Server-2008、IIS7.0环境下配置伪静态化
在Windows-Server-2008.IIS7.0环境下配置伪静态化 首先,是IIS7.0的配置,由于Windows Server 2008操作系统默认的IIS版本为 ...
- Deutsch lernen (08)
1. empfehlen - empfahl - hat empfohlen 推荐:劝说,劝告 Können Sie mir einen guten Artz empfehlen? jemand e ...
- css属性代码大全总结(一)
一 CSS文字属性: color : #999999; /*文字颜色*/ font-family : 宋体,sans-serif; /*文字字体*/ font-size : 9pt; /*文字大小*/ ...
- QT显示框架嵌入Vs控制台工程
一.一些准备工作: 1.安装Qt for VS 的插件: 安装Qt for VS 的插件 下载地址:http://download.qt.io/official_releases/vsaddin/ ...