ACM-ICPC北京賽區2017網絡同步賽H

http://hihocoder.com/contest/icpcbeijing2017/problem/8

預處理暴力枚舉修改的點

#include <bits/stdc++.h>
using namespace std;
const int maxn = 159;
const int inf = 0x3f3f3f3f;
int a[maxn][maxn];
int colsum[maxn][maxn];
int rowsum[maxn][maxn];
int dp[maxn];
int up[maxn],down[maxn],rig[maxn],lef[maxn];
int main()
{int n,m,p;while(~scanf("%d%d%d",&n,&m,&p)){memset(up,-inf,sizeof(up));memset(down,-inf,sizeof(down));memset(rig,-inf,sizeof(rig));memset(lef,-inf,sizeof(lef));for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){scanf("%d",&a[i][j]);colsum[i][j] = colsum[i-1][j]+a[i][j];rowsum[i][j] = rowsum[i][j-1]+a[i][j];}}int ans = -inf;for(int i=1;i<=n;i++){for(int j=i;j<=n;j++){dp[0] = -inf;for(int k=1;k<=m;k++){int tmp  =colsum[j][k]-colsum[i-1][k];dp[k] = max(dp[k-1]+tmp,tmp);ans = max(ans,dp[k]);lef[k] = max(lef[k],dp[k-1]);}}}for(int i=1;i<=n;i++){for(int j=i;j<=n;j++){dp[m+1] = -inf;for(int k=m;k>=1;k--){int tmp  =colsum[j][k]-colsum[i-1][k];dp[k] = max(dp[k+1]+tmp,tmp);rig[k] = max(rig[k],dp[k+1]);}}}for(int i=1;i<=m;i++){for(int j=i;j<=m;j++){dp[0] = -inf;for(int k=1;k<=n;k++){int tmp  =rowsum[k][j]-rowsum[k][i-1];dp[k] = max(dp[k-1]+tmp,tmp);up[k] = max(up[k],dp[k-1]);}}}for(int i=1;i<=m;i++){for(int j=i;j<=m;j++){dp[n+1] = -inf;for(int k=n;k>=1;k--){int tmp  =rowsum[k][j]-rowsum[k][i-1];dp[k] = max(dp[k+1]+tmp,tmp);down[k] = max(down[k],dp[k+1]);}}}for(int i=1;i<=m;i++){lef[i] = max(lef[i],lef[i-1]);}for(int i=m;i>=1;i--){rig[i] = max(rig[i],rig[i+1]);}for(int i=1;i<=n;i++){up[i] = max(up[i],up[i-1]);}for(int i=n;i>=1;i--){down[i] = max(down[i],down[i+1]);}int ret = ans;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){int tmp = max(up[i],down[i]);tmp  = max(tmp,lef[j]);tmp = max(tmp,rig[j]);tmp = max(tmp,ans-a[i][j]+p);ret = min(ret,tmp);}}printf("%d\n",ret);}return 0;
}
/*
1 4 -1
3 -2 5 9
*/

  

轉載于:https://www.cnblogs.com/tjucxz/p/8849612.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390677.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390677.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390677.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

PPPOE撥號上網流程及密碼竊取具體實現

樓主學生黨一枚&#xff0c;最近研究netkeeper有些許心得。 關于netkeeper是調用windows的rasdial來進行上網的東西&#xff0c;網上已經有一大堆&#xff0c;我就不贅述了。 本文主要講解rasdial的部分核心過程&#xff0c;以及我們可以利用它來干些什么。 netkeeper中rasdial…

leetcode 160. 相交鏈表(雙指針)

給你兩個單鏈表的頭節點 headA 和 headB &#xff0c;請你找出并返回兩個單鏈表相交的起始節點。如果兩個鏈表沒有交點&#xff0c;返回 null 。 圖示兩個鏈表在節點 c1 開始相交&#xff1a; 題目數據 保證 整個鏈式結構中不存在環。 注意&#xff0c;函數返回結果后&#…

android開發入門_Android開發入門

android開發入門Android is an open source, Linux-based mobile operating system. Android was developed by the Open Handset Alliance, which was lead by Google and featured contributions from many other companies.Android是基于Linux的開放源代碼移動操作系統。 An…

新購阿里云服務器ECS創建之后無法ssh連接的問題處理

作者&#xff1a;13 GitHub&#xff1a;https://github.com/ZHENFENG13 版權聲明&#xff1a;本文為原創文章&#xff0c;未經允許不得轉載。 問題描述 由于原服務器將要到期&#xff0c;因此趁著阿里云搞促銷活動重新購買了一臺ECS服務器&#xff0c;但是在初始化并啟動后卻無…

數據下發非標準用戶權限測試

與同事一起溝通了下MDM的Oracle權限部分: create user cx default tablespace cwbaseoe73 identified by Test6530 grant select,update,delete,insert on lcoe739999.lsbzdw to cx grant create table to cx alter user cx quota unlimited on cwbaseoe73 grant create sessio…

leetcode 474. 一和零(dp)

給你一個二進制字符串數組 strs 和兩個整數 m 和 n 。 請你找出并返回 strs 的最大子集的大小&#xff0c;該子集中 最多 有 m 個 0 和 n 個 1 。 如果 x 的所有元素也是 y 的元素&#xff0c;集合 x 是集合 y 的 子集 。 示例 1&#xff1a; 輸入&#xff1a;strs [“10”…

邊緣計算 ai_在邊緣探索AI!

邊緣計算 ai介紹 (Introduction) What is Edge (or Fog) Computing?什么是邊緣(或霧)計算&#xff1f; Gartner defines edge computing as: “a part of a distributed computing topology in which information processing is located close to the edge — where things a…

JavaScript中的全局變量介紹

Global variables are declared outside of a function for accessibility throughout the program, while local variables are stored within a function using var for use only within that function’s scope. If you declare a variable without using var, even if it’…

初識spring-boot

使用Spring或者SpringMVC的話依然有許多東西需要我們進行配置&#xff0c;這樣不僅徒增工作量而且在跨平臺部署時容易出問題。 使用Spring Boot可以讓我們快速創建一個基于Spring的項目&#xff0c;而讓這個Spring項目跑起來我們只需要很少的配置就可以了。Spring Boot主要有如…

leetcode 879. 盈利計劃(dp)

這是我參與更文挑戰的第9天 &#xff0c;活動詳情查看更文挑戰 題目 集團里有 n 名員工&#xff0c;他們可以完成各種各樣的工作創造利潤。 第 i 種工作會產生 profit[i] 的利潤&#xff0c;它要求 group[i] 名成員共同參與。如果成員參與了其中一項工作&#xff0c;就不能…

區塊鏈101:區塊鏈的應用和用例是什么?

區塊鏈技術是一場記錄系統的革命。 比特幣是歷史上第一個永久的、分散的、全球性的、無信任的記錄分類帳。自其發明以來&#xff0c;世界各地各行各業的企業家都開始明白這一發展的意義。 區塊鏈技術的本質讓人聯想到瘋狂&#xff0c;因為這個想法現在可以應用到任何值得信賴的…

java請求接口示例_用示例解釋Java接口

java請求接口示例介面 (Interfaces) Interface in Java is a bit like the Class, but with a significant difference: an interface can only have method signatures, fields and default methods. Since Java 8, you can also create default methods. In the next block y…

如何建立搜索引擎_如何建立搜尋引擎

如何建立搜索引擎This article outlines one of the most important search algorithms used today and demonstrates how to implement it in Python in just a few lines of code.本文概述了當今使用的最重要的搜索算法之一&#xff0c;并演示了如何僅用幾行代碼就可以在Pyth…

用Docker自動構建紙殼CMS

紙殼CMS可以運行在Docker上&#xff0c;接下來看看如何自動構建紙殼CMS的Docker Image。我們希望的是在代碼提交到GitHub以后&#xff0c;容器鏡像服務可以自動構建Docker Image&#xff0c;構建好以后&#xff0c;就可以直接拿這個Docker Image來運行了。 Dockerfile 最重要的…

Linux學習筆記15—RPM包的安裝OR源碼包的安裝

RPM安裝命令1、 安裝一個rpm包rpm –ivh 包名“-i” : 安裝的意思“-v” : 可視化“-h” : 顯示安裝進度另外在安裝一個rpm包時常用的附帶參數有&#xff1a;--force : 強制安裝&#xff0c;即使覆蓋屬于其他包的文件也要安裝--nodeps : 當要安裝的rpm包依賴其他包時&#xff0…

leetcode 518. 零錢兌換 II

給定不同面額的硬幣和一個總金額。寫出函數來計算可以湊成總金額的硬幣組合數。假設每一種面額的硬幣有無限個。 示例 1: 輸入: amount 5, coins [1, 2, 5] 輸出: 4 解釋: 有四種方式可以湊成總金額: 55 5221 52111 511111 示例 2: 輸入: amount 3, coins [2] 輸出: 0 解…

軟件測試中什么是正交實驗法_軟件工程中的正交性

軟件測試中什么是正交實驗法正交性 (Orthogonality) In software engineering, a system is considered orthogonal if changing one of its components changes the state of that component only. 在軟件工程中&#xff0c;如果更改系統的組件之一僅更改該組件的狀態&#xf…

leetcode 279. 完全平方數(dp)

題目一 給定正整數 n&#xff0c;找到若干個完全平方數&#xff08;比如 1, 4, 9, 16, …&#xff09;使得它們的和等于 n。你需要讓組成和的完全平方數的個數最少。 給你一個整數 n &#xff0c;返回和為 n 的完全平方數的 最少數量 。 完全平方數 是一個整數&#xff0c;其…

github代碼_GitHub啟動代碼空間

github代碼Codespaces works like a virtual Integrated Development Environment (IDE) on the cloud.代碼空間的工作方式類似于云上的虛擬集成開發環境(IDE)。 Until now, you had to make a pull request to contribute to a project. This required setting up the enviro…

php變量

什么叫變量&#xff1f; 變量可以通過變量名訪問。在指令式語言中&#xff0c;變量通常是可變的&#xff1b; 這里就先這么簡單理解&#xff0c;通過對語言的研究會更加的理解變量的其他意義。 在PHP中變量是用于存儲信息的"容器"&#xff1a; <?php $x5; $y6;…