codeforces#FF(div2) D DZY Loves Modification_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 12:02:03
原创
1290人浏览过

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

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

这个用优先队列维护,没选择一行(列)后将这行(列)的和减去相应的np (mp)重新加入队列


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

立即学习前端免费学习笔记(深入)”;

jQuery仿d站首页效果
jQuery仿d站首页效果

jQuery仿d站首页效果

jQuery仿d站首页效果 171
查看详情 jQuery仿d站首页效果

既然顺序无关,可以看做先选择完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 * xtypedef 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 21 2 3 102 3 5 22 2 22 2 2*/
登录后复制


HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号