A Refining Company LightOJ - 1036
A Refining Company LightOJ - 1036
描述好长啊...
题意:在m*n的矩阵上,每一格摆一个向上或者向左的传送带(不能同时摆,只能摆一个)。同时,每一格有两种物资Uranium和Radium。会给出两个矩阵,分别表明每一格Uranium和Radium的数量。每一种物资可以通过传送带按照其方向传送,但不能转向(遇到不同方向的传送带物品就失效)。Radium要送到上面(第一行任意位置),Uranium要送到左面(左起第一列任意位置),送到错误位置的物资将废弃。求最终送到正确位置的物资数量总和的最大值。
方法:容易发现,最大结果所对应的传送带方向中,一定不会有某个向左的传送带在任何向上的传送带的右侧或上侧,不然将其变为向上的传送带结果一定不会变差;一定不会有某个向上的传送带在任何向左的传送带的左侧或下侧,不然将其变为向左的传送带结果一定不会变差。
因此,状态ans[i][j]表示第i行前j列向左时最大得分。
sumu[i][j]表示第i行前j列以外的格子的向上得分之和
suml[i][j]表示第i行前j列的向左得分之和
那么,$ans[i][j]=max\{ans[i-1][p]\}(0<=p<=j)+suml[i][j]+sumu[i][j]$。预处理sumu和suml是不难的。计算ans时,随便在算同一行的时候用奇怪的方法(应该叫...前缀max?)记录一下max就是$O(mn)$。答案就是最后一行ans的最大值。
#include<cstdio>
#include<algorithm>
using namespace std;
int T,TT,m,n,t_max;
int l[][],u[][],suml[][],sumu[][],ans[][];
int main()
{
int i,j;
scanf("%d",&T);
for(TT=;TT<=T;TT++)
{
scanf("%d%d",&m,&n);
for(i=;i<=m;i++)
for(j=;j<=n;j++)
scanf("%d",&l[i][j]);
for(i=;i<=m;i++)
for(j=;j<=n;j++)
scanf("%d",&u[i][j]);
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
suml[i][j]=suml[i][j-]+l[i][j];
sumu[i][n]=;
for(j=n-;j>=;j--)
sumu[i][j]=sumu[i][j+]+u[i][j+];
}
for(j=;j<=n;j++)
ans[][j]=suml[][j]+sumu[][j];
for(i=;i<=m;i++)
{
t_max=;
for(j=;j<=n;j++)
{
t_max=max(t_max,ans[i-][j]);
ans[i][j]=t_max+suml[i][j]+sumu[i][j];
}
}
t_max=;
for(j=;j<=n;j++)
t_max=max(t_max,ans[m][j]);
printf("Case %d: %d\n",TT,t_max);
}
return ;
}
A Refining Company LightOJ - 1036的更多相关文章
- 1036 - A Refining Company
1036 - A Refining Company PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...
- lightoj 1036 - A Refining Company(简单dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1036 题解:设dp[i][j]表示处理到(i,j)点时的最大值然后转移显然是 ...
- Light OJ 1036 - A Refining Company
题目大意: 一个m*n的矩阵,里面有两种矿物质铀和镭,现在要把铀和镭运送到指定位置.北边是炼镭厂,西边是了炼铀厂. 现在要建立传送带,传送带有两种,一种是从东到西,另一种是从南到北,传送带不能交叉,并 ...
- lightoj 1036 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1036 #include <cstdio> #include <cst ...
- LightOJ1036 A Refining Company(DP)
题目大概说有一个n*m的格子地图,每个格子有铀或者镭矿.地图最北面的镭矿加工厂,最西面有铀矿加工厂,而要通过在格子里铺设由南向北(镭)或由东向西(铀)的轨道来送矿物到加工厂.一个格子只能铺设一种轨道, ...
- dp百题大过关(第一场)
好吧,这名字真是让我想起了某段被某教科书支配的历史.....各种DP题层出不穷,不过终于做完了orz 虽然各种手糊加乱搞,但还是要总结一下. T1 Monkey Banana Problem 这 ...
- LightOj 1221 - Travel Company(spfa判负环)
1221 - Travel Company PDF (English) Statistics problem=1221" style="color:rgb(79,107,114)& ...
- (状压) Marriage Ceremonies (lightOJ 1011)
http://www.lightoj.com/volume_showproblem.php?problem=1011 You work in a company which organizes mar ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
随机推荐
- WPF绑定各种数据源之object数据源
一.WPF绑定各种数据源索引 WPF 绑定各种数据源之Datatable WPF绑定各种数据源之object数据源 WPF绑定各种数据源之xml数据源 WPF绑定各种数据源之元素控件属性 Bindin ...
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo DP+矩阵快速幂加速
E. Okabe and El Psy Kongroo Okabe likes to take walks but knows that spies from the Organization ...
- Client should know only resource URIs and that’s all.
REST Principles and Architectural Constraints – REST API Tutorial https://restfulapi.net/rest-archit ...
- Continuous integration: The answer to life, the universe, and everything?
Continuous integration is not always the right answer. Here's why. https://techbeacon.com/continuous ...
- gcc 头文件是用户应用程序和函数库之间的桥梁和纽带 功能的真正逻辑实现是以硬件层为基础
gcc GCC, the GNU Compiler Collection - GNU Project - Free Software Foundation (FSF) http://gcc.gnu.o ...
- C# List Find方法
https://blog.csdn.net/knqiufan/article/details/77847143
- git push & git pull 推送/拉取指定分支
https://blog.csdn.net/litianze99/article/details/52452521
- 一个基本的spring+mybatis所需要的包
spring+mybatis需要的包:org.springframework.spring-webmvc(spring框架DispatcherServlet需要,spring-webmvc会依赖spr ...
- Why is an 'Any CPU' application running as x86 on a x64 machine?
It's likely that you linked some assemblies that are not Any CPU, but include native code (or are ...
- string interpolation in sql server
https://sqlserver.dev129.com/2018/01/29/string-interpolation-in-t-sql/ Most programming languages ha ...