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 ...
随机推荐
- E20170911-hm
specification n. 规格; 说明书; 详述;
- python-day3 元组(tuple),列表(list),字典(dict)
1.元组 tuple 有序数据,元组数据不可更改,若元组中有列表,可更改元组中的列表值里的值 元组中以","分开,若只有一个值就不是元组 包含各种数据类型 索引取值:t(2,0.0 ...
- C - Arrival of the General
Problem description A Ministry for Defense sent a general to inspect the Super Secret Military Squad ...
- ASP.net获取当前url各种属性(文件名、参数、域名等)的方法
假设当前页完整地址是:http://www.test.com/aaa/bbb.aspx?id=5&name=kelli "http://"是协议名 "www.te ...
- 如何实现MySQL数据库使用情况的审计
如何实现MySQL数据库使用情况的审计 最佳答案 mysql的审计功能 mysql服务器自身没有提供审计功能,但是我们可以使用init-connect + binlog的方法进行mysql的操 ...
- 学习Spider 了解 Scrapy的流程
Scrapy 先创建项目 在windows下 scrapy startproject myproject #myproject是你的项目名称 cd 项目名称 scrapy g ...
- shell常用语法
for.if条件: https://blog.51cto.com/qiufengsong/1252889 一.for循环: );do echo $i done ###第一行:seq是指1到10,第二行 ...
- 关于 docsify ssr 的研究
关于 docsify ssr 的研究 docsify 虽然不错, 但是不支持 seo .官网虽然提供 seo 的一个简单示例, 但总总问题在 issues 中无人解答. 今天再次尝试, 解决了 ind ...
- NOIP2016 DAY2 T2蚯蚓
传送门 Description 本题中,我们将用符号[c]表示对c向下取整,例如:[3.0」= [3.1」=[3.9」=3.蛐蛐国最近蚯蚓成灾了!隔壁跳 蚤国的跳蚤也拿蚯蚓们没办法,蛐蛐国王只好去请神 ...
- [模板]FFT
郝神并没有令我明白这个. 但是巨神的题解太强了. #include <iostream> #include <complex> #include <cmath> # ...