题目:假如有A,B两个人,在一个m*n的矩阵,然后A在(1,1),B在(m,1),A要走到(m,n),B要走到(1,n),两人走的过程中可以捡起格子上的数字,而且两人速度不一样,可以同时到一个点(哪怕这个点离A很近,离B很远),现在A,B起码相遇于一个点点,相遇点的数字A,B都得不到,求最后A,B总数字之和的最大值

B. Working out
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix
a with n lines and
m columns. Let number
a[i][j] represents the calories burned by performing workout at the cell of gym in the
i-th line and the j-th column.
Iahub starts with workout located at line 1 and column
1. He needs to finish with workout
a[n][m]. After finishing workout
a[i][j], he can go to workout
a[i + 1][j] or a[i][j + 1]. Similarly, Iahubina starts with workout
a[n][1] and she needs to finish with workout
a[1][m]. After finishing workout from cell
a[i][j], she goes to either
a[i][j + 1] or
a[i - 1][j].
There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.
If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of
 cells that they use to reach meet cell may differs.
Input
The first line of the input contains two integers n and
m (3 ≤ n, m ≤ 1000). Each of the next
n lines contains m integers:
j-th number from i-th line denotes element
a[i][j] (0 ≤ a[i][j] ≤ 105).
Output
The output contains a single number — the maximum total gain possible.
Sample test(s)
Input
3 3
100 100 100
100 1 100
100 100 100
 
Output
800
/*
思路:
要找最大值,那么只能有一个相遇点
如果用两个数组再来枚举相遇点是不可能的
所以比如说左上到右下,可以换成左上到相遇点,右下到相遇点
另一条路线也是如此 枚举各种可能的相交点,那么从左下角走到相交点或者从左上角走到
相交点的各种情况很容易用for写出来
可是从相交点到终点不好写,因为相交点是枚举的,
相当于未知,
逆向思维:从相交点到终点==从终点到相交点
而终点只有两个,递推就是要从已知到未知
那么这题就转换成从四个边角点到未知点
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=+;
ll f[maxn][maxn]={},dp1[maxn][maxn],dp2[maxn][maxn],dp3[maxn][maxn],dp4[maxn][maxn];
int main()//定义数组f存基础数字,dp1代表从左上角递推
//dp2左下角,dp3右下角,dp4右上角
{
//输入环节
ll m,n;
cin>>m>>n;
for(ll i=;i<=m;i++)
for(ll j=;j<=n;j++)
{
scanf("%lld",&f[i][j]);
} //处理环节
dp1[][]=f[][];//对dp1边缘赋值,即左边和上边两面墙赋入初始值
for(ll i=;i<=m;i++)
dp1[i][]+=f[i][]+dp1[i-][];
for(ll j=;j<=n;j++)
dp1[][j]+=f[][j]+dp1[][j-]; dp2[m][]=f[m][];//对dp2边缘赋值
for(ll i=m-;i>=;i--)
dp2[i][]+=f[i][]+dp2[i+][];
for(ll j=;j<=n;j++)
dp2[m][j]+=f[m][j]+dp2[m][j-]; dp4[][n]=f[][n];//对dp4边缘赋值
for(ll i=;i<=m;i++)
dp4[i][n]+=f[i][n]+dp4[i-][n];
for(ll j=n-;j>=;j--)
dp4[][j]+=f[][j]+dp4[][j+]; dp3[m][n]=f[m][n];//对dp3边缘赋值
for(ll i=m-;i>=;i--)
dp3[i][n]+=f[i][n]+dp3[i+][n];
for(ll j=n-;j>=;j--)
dp3[m][j]+=f[m][j]+dp3[m][j+]; for(ll i=;i<=m;i++)//让i从2到m,j从2到n
for(ll j=;j<=n;j++)//下面再通过调一下下标与i,j的关系实现同时处理四个数组
{
dp1[i][j]+=f[i][j]+max(dp1[i-][j],dp1[i][j-]);
dp4[i][n-j+]+=f[i][n-j+]+max(dp4[i][n-j++],dp4[i-][n-j+]);
dp2[m-i+][j]+=f[m-i+][j]+max(dp2[m-i++][j],dp2[m-i+][j+]);
dp3[m-i+][n-j+]+=f[m-i+][n-j+]+max(dp3[m-i++][n-j+],dp3[m-i++][n-i++]);
}//dp1从左下角开始递推,dp2,3,4也从其他三个角开始递推
ll ans=;
for(ll i=;i<=m;i++)//这里两个for循环枚举相遇点
for(ll j=;j<=n;j++)
{
ans=max(ans,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-*f[i][j]);
}//如果[i][j]是相遇点,那么f[i][j]在dp1,dp2,dp3,dp4都被多拿了
//(相遇点的数字不能拿,所以要减去4*f[i][j])
cout<<ans<<endl;
return ;
/*********************这里预备一串代码输出dp1到dp4后来的具体情况
可以自己用来检验dp1到dp4是否和自己想想的结果一样
printf("\n");
for(ll i=1;i<=m;i++)
for(ll j=1;j<=n;j++)
{
printf("%lld ",dp1[i][j]);
if(j==3)printf("\n");
}
printf("\n");
for(ll i=1;i<=m;i++)
for(ll j=1;j<=n;j++)
{
printf("%lld ",dp2[i][j]);
if(j==3)printf("\n");
}
printf("\n");
for(ll i=1;i<=m;i++)
for(ll j=1;j<=n;j++)
{
printf("%lld ",dp3[i][j]);
if(j==3)printf("\n");
}printf("\n");
for(ll i=1;i<=m;i++)
for(ll j=1;j<=n;j++)
{
printf("%lld ",dp4[i][j]);
if(j==3)printf("\n");
}printf("\n");
************************/ }

四角递推(CF Working out,动态规划递推)的更多相关文章

  1. 最长上升子序列(动态规划递推,LIS)

    1759:最长上升子序列 题目: 总时间限制: 2000ms 内存限制: 65536kB 描述 一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列是上升的 ...

  2. 最大子段和(洛谷P1115,动态规划递推)

    洛谷题目链接 题目赋值出来格式有问题,所以我就只放题目链接了 下面为ac代码 #include<bits/stdc++.h> #define ll long long using name ...

  3. 【Luogu4723】线性递推(常系数齐次线性递推)

    [Luogu4723]线性递推(常系数齐次线性递推) 题面 洛谷 题解 板子题QwQ,注意多项式除法那里每个多项式的系数,调了一天. #include<iostream> #include ...

  4. 推送通知/传感器/UIDynamic仿真(推送通知已适配iOS10)

    推送通知/传感器/UIDynamic 一.推送通知 1.推送通知简介 什么是推送通知 此处的推送通知与NSNotification没有任何关系 可以理解为,向用户推送一条信息来通知用户某件事情 作用: ...

  5. iOS的推送机制APNs:本地推送&远程推送

    本地推送: 本地推送主要应用在备忘录,闹钟等本地的,基于时间定时的消息提醒.本篇不做详细描述. 远程推送:APNS(苹果推送通知服务) iOS远程推送机制的原理及流程: 注册推送(橙色部分):若该Ap ...

  6. 与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知

    原文:与众不同 windows phone (9) - Push Notification(推送通知)之概述, 推送 Toast 通知 [索引页][源码下载] 与众不同 windows phone ( ...

  7. Windows Phone开发(43):推送通知第一集——Toast推送

    原文:Windows Phone开发(43):推送通知第一集--Toast推送 好像有好几天没更新了,抱歉抱歉,最近"光荣"地失业,先是忙于寻找新去处,唉,暂时没有下文.而后又有一 ...

  8. 推送之HelloWorld及个推Smart Push

    最近有个朋友想要推送一些消息到自己的APP上,自己用了HTTP轮询的方式比较耗电,也比较占用流量,一旦用户关闭了进程,消息则很难触达,于是,咨询我有没有什么好的解决方案.我告诉他其实可以使用推送,他瞪 ...

  9. java推送数据到app--极光推送

    之前项目有用到需要把数据推送到app端 采用的是极光推送 特此把工具类和pom.xml需要的jar整理如下 pom.xml需要jar如下 <!-- 极光推送 --> <depende ...

随机推荐

  1. what is Servlet Container[转载]

    1 在这个博客中,我将描述一下web服务器.Servlet容器的基本概念,以及Servlet容器和jvm之间的关系.我想要证明的是Servlet容器不过就是一个java程序. 2 什么是web服务器 ...

  2. ios20--xib2

    故事板控制器: // // ViewController.m // 03-通过xib自定义商品的View #import "ViewController.h" #import &q ...

  3. spi和I2c的速率

    I2C协议v2.1规定了100K,400K和3.4M三种速率(bps).SPI是一种事实标准,由Motorola开发,并没有一个官方标准.已知的有的器件SPI已达到50Mbps.具体到产品中SPI的速 ...

  4. Linux/Android——input子系统核心 (三)【转】

    本文转载自:http://blog.csdn.net/jscese/article/details/42123673 之前的博客有涉及到linux的input子系统,这里学习记录一下input模块. ...

  5. python datatime日期和时间值模块

    datetime.time():是一个时间类,这个类接受4个参数,分别代表时,分,秒,毫秒.参数的默认值是为0 #!/usr/bin/env python #coding:utf8 import da ...

  6. 35. extjs MessageBox里fn:是什么意思

    function的缩写,用来指定回调函数,就是你点击确定或取消按钮之类的按钮以后触发的事件Ext.Msg.show({ title:'自定义消息框', msg:'这是一个自定义消息框,想怎么搞就怎么搞 ...

  7. 16. Ext.ux.TabCloseMenu插件的使用(TabPanel右键关闭菜单) 示例

    转自:https://crabdave.iteye.com/blog/327978 Ext.ux.TabCloseMenu插件的使用(TabPanel右键关闭菜单) 示例 效果: 创建调用的HTML: ...

  8. mysql status关键字 数据表设计中慎重使用

    mysql status关键字  数据表设计中慎重使用

  9. Spring中AOP的两种代理方式(Java动态代理和CGLIB代理-转载

    内容是摘抄的,不知最初的原作者,见谅 Java 动态代理.具体有如下四步骤: 通过实现 InvocationHandler 接口创建自己的调用处理器: 通过为 Proxy 类指定 ClassLoade ...

  10. Ubuntu服务器WDCP可视化界面搭建注意

    title: Ubuntu服务器WDCP可视化界面搭建注意 前两天心血来潮,研究了下服务器搭建与部署. 领了个免费体验3天的vps服务器进行了实操. 在安装WDCP的时候遇到了些问题,网上大部分对问题 ...