链接: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 贪心+优先队列的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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. ...

  4. 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] + ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. A. Jeff and Digits(cf)

    A. Jeff and Digits time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. AMD 与 CMD 区别

    作者:玉伯链接:https://www.zhihu.com/question/20351507/answer/14859415来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...

  3. javascript从作用域链的角度看闭包

    闭包 闭包是一个能访问外部函数定义的变量的函数. 为什么? 当访问一个变量时,解释器会首先在当前作用域查找标示符,如果没有找到,就去父作用域找,直到找到该变量的标示符或者不再存在父作用域了,这就是作用 ...

  4. 《CSS Mastery》读书笔记(3)

    第三章 可视化格式模型 三个最重要的CSS概念需要掌握,浮动floating,定位positioning, 框模型(有些书翻译成盒子模型)box model. 这些概念控制了元素在页面中的安放和显示. ...

  5. 1C课程笔记分享_StudyJams_2017

    课程1C 概述 课程1C是创建一个生日贺卡应用的实践课程,所以本篇笔记分享主要记录个人的实践过程,此外分享一些比较零散的知识点. Drawable文件夹 Drawable文件夹是Android项目统一 ...

  6. Runtime的相关知识

    Runtime是近年来面试遇到的一个高频方向,也是我们平时开发中或多或少接触的一个领域,那么什么是runtime呢?它又可以用来做什么呢? 什么是Runtime?平时项目中有用过么? OC是一门动态性 ...

  7. 【原创】你知道Oracle 10G能存多少数据吗

    昨天晚上在看Oracle 10G联机文档中关于bigfile tablespaces的描述(引用1),发现了关于Oracle存储极限的简单描述.bigfile tablespaces的存在,让Orac ...

  8. BSGS-BabyStepGiantStep算法+拓展

    学习数学真是一件赛艇的事. BSGS名字听起来非常有意思,力拔山兮气盖世,北上广深,小步大步...算法其实更有意思,它是用来求解一个方程的 A^x ≡ B (mod P) 是不是特别眼熟,有几个式子长 ...

  9. git解决内容冲突

    内容冲突的冲突处理 两个用户修改了同一个文件的同一块区域,git会报告内容冲突. 解决办法:打开发生冲突的文件,会发现 <<<<<<< HEADtest in ...

  10. sql 导入excel 遇到问题

    ALTER TABLE tab1 add id int identity primary key (注意:必须加identity,否则添加会失败) //导入excel时候 先把主键去掉 变为可为空,之 ...