The Urge to Merge

Time Limit: 1000MS Memory limit: 65536K

题目描述

The Acme Consulting Group has sent you into a new technology park to enhance dynamism, synergy and sustainability. You\'re not sure what any of these terms mean, but you\'re pretty good at making money, which is what you plan on doing. The park consists of a 3 × n grid of facilities. Each facility houses a start-up with an inherent value. By facilitating mergers between neighboring start-ups, you intend to increase their value, thereby allowing you to fulfill your life-long dream of opening your own chain of latte-and-burrito shops.

Due to anti-trust laws, any individual merger may only involve two start-ups and no start-up may be involved in more than one merger. Furthermore, two start-ups may only merge if they are housed in adjacent facilities (diagonal doesn\'t count). The added value generated by a merger is equal to the product of the values of the two start-ups involved. You may opt to not involve a given start-up in any merger, in which case no added value is generated. Your goal is to find a set of mergers with the largest total added value generated. For example, the startup values shown in the figure on the left, could be optimally merged as shown in the figure on the right for a total added value of 171.
                                   

输入

 The first line of each test case will contain a single positive integer n ≤1000 indicating the width of the facilities grid. This is followed by three lines, each containing n positive integers (all ≤ 100) representing the values of each start-up. A line containing a single 0 will terminate input.

输出

 For each test case, output the maximum added value attainable via mergers for that set of start-ups.

示例输入

4
7  2  4  9
3  5  9  3
9  5  1  8
0

示例输出

Case 1: 171

提示

来源

中国海洋大学第四届朗讯杯高级组

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2725

当时比赛的时候看到这道题觉得是道DP,但是因为没有重视高度为3这个条件,想不明白从左上到右下该怎么推,也就没再多考虑。

后来重看这个题,发现整个递推过程只需要从左往右即可。整个dp过程也不难。

以第i列结束的使用的方块,一共有11种形态。不同形态可以从第i-2,第i-1的不同形态转移。

一开始有个地方漏了一点以至于狂WA不止,后来终于发现才AC了。。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[1005][15];
int grid[5][1005];
int n;
int Convers(int v,int a)
{
switch(v)
{
case 1:
return grid[1][a-1]*grid[1][a];
case 2:
return grid[2][a-1]*grid[2][a];
case 3:
return grid[3][a-1]*grid[3][a];
case 4:
return grid[2][a-1]*grid[2][a]+grid[3][a-1]*grid[3][a];
case 5:
return grid[1][a-1]*grid[1][a]+grid[3][a-1]*grid[3][a];
case 6:
return grid[1][a-1]*grid[1][a]+grid[2][a-1]*grid[2][a];
case 7:
return grid[1][a-1]*grid[1][a]+grid[2][a-1]*grid[2][a]+grid[3][a-1]*grid[3][a];
case 8:
return grid[1][a]*grid[2][a];
case 9:
return grid[2][a]*grid[3][a];
case 10:
return grid[1][a-1]*grid[1][a]+ grid[2][a]*grid[3][a];
case 11:
return grid[3][a-1]*grid[3][a]+ grid[1][a]*grid[2][a];
}
}
int main()
{
int kase=0;
while(scanf("%d",&n)==1&&n)
{
memset(grid,0,sizeof(grid));
for(int i=1; i<=3; ++i)
for(int j=1; j<=n; ++j)
scanf("%d",&grid[i][j]);
memset(dp,0,sizeof(dp));
for(int i=1; i<=n; ++i)
{
for(int j=1; j<=11; ++j)
{
int res=0;
if(i>1)
{
switch(j)
{
case 1:
res=max(res,max(dp[i-1][2],max(dp[i-1][3],max(dp[i-1][4],dp[i-1][9]))));
break;
case 2:
for(int k=1; k<=11; ++k)
res=max(res,dp[i-2][k]);
res=max(res,max(dp[i-1][1],max(dp[i-1][3],dp[i-1][5])));
break;
case 3:
res=max(res,max(dp[i-1][1],max(dp[i-1][2],max(dp[i-1][6],dp[i-1][8]))));
break;
case 4:
res=max(res,dp[i-1][1]);
for(int k=1; k<=11; ++k)
res=max(res,dp[i-2][k]);
break;
case 5:
res=max(res,dp[i-1][2]);
for(int k=1; k<=11; ++k)
res=max(res,dp[i-2][k]);
break;
case 6:
res=max(res,dp[i-1][3]);
for(int k=1; k<=11; ++k)
res=max(res,dp[i-2][k]);
break;
case 7:
for(int k=1; k<=11; ++k)
res=max(res,dp[i-2][k]);
break;
case 8:
for(int k=1; k<=11; ++k)
res=max(res,dp[i-1][k]);
break;
case 9:
for(int k=1; k<=11; ++k)
res=max(res,dp[i-1][k]);
break;
case 10:
res=max(res,max(dp[i-1][2],max(dp[i-1][3],max(dp[i-1][4],dp[i-1][9]))));
break;
case 11:
res=max(res,max(dp[i-1][1],max(dp[i-1][2],max(dp[i-1][6],dp[i-1][8]))));
break;
}
}
if(i==1)
{
if(j==8||j==9)
dp[i][j]=Convers(j,i);
else
dp[i][j]=0;
}
else
dp[i][j]=res+Convers(j,i);
}
}
int ans=0;
for(int i=1; i<=11; ++i)
ans=max(dp[n][i],ans);
printf("Case %d: ",++kase);
printf("%d\n",ans);
}
return 0;
}

中国海洋大学第四届朗讯杯高级组 The Urge to Merge相关推荐

  1. 中国海洋大学第四届朗讯杯高级组 Cash Cow

    Time Limit: 1000MS    Memory limit: 65536K 题目描述 Years before Candy Crush became the wildly popular g ...

  2. 中国海洋大学第四届朗讯杯高级组 Playing Fair with Cryptography

    Playing Fair with Cryptography Time Limit: 1000MS    Memory limit: 65536K 题目描述 Encryption is the pro ...

  3. 中国海洋大学第四届朗讯杯高级组 I Cuckoo for Hashing

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2719&cid=1203 题意 :意思就是哈希来的,具体大意就是说有两个哈希表,然后有这样 ...

  4. 中国海洋大学第四届朗讯杯高级组 A 2718 Rocky(模拟)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2718 题意:优先直走,右 左 后.... ...

  5. 多项式求和(中国海洋大学第三届“朗讯杯”编程比赛高级组试题)

    Problem Description 多项式描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 -- 先请你求出多项式前n项的和. Input 第一行输入一个数T代表测试数据 ...

  6. 中国海洋大学c语言题库,2014级中国海洋大学C语言上机题库与答案.docx

    2014级中国海洋大学C语言上机题库与答案 2014中国海洋大学C语言上机考试题库以及答案(20套)编写函数long fun(long x),它的功能是:将长整型参数x中每一位上为偶数的数依次取出,构 ...

  7. 阿尔卡特-朗讯合并背后的中国威胁

    华尔街日报中文网络版报道,法国一家一流电讯设备制造商日前传出要与其长期以来的美国竞争对手合并的消息,而促使该公司考虑这宗交易的正是来自中国企业的日甚一日的威胁. 总部位于巴黎的阿尔卡特公司(Alcat ...

  8. 卓望控股公司CEO谢峰:让卓望成为朗讯

    卓望专门为移动梦网打造数据业务管理平台,这个市场有百亿之大,目前只有卓望公司一家在做 卓望领导层力排众议,提出一个拿公司10%的估值作为股份向全体员工发放期权的计划 ,为上市融资排除了最后障碍 谢峰, ...

  9. 2021年中国海洋大学计算机及电子信息考研成绩分析

    考研时间跨度: 海大计算机考研老哥qq:1151039635 初试时间: 2020年9月16发布海大招生专业目录 网上报名时间为2020年10月10日至10月31日,每天9:00-22:00. 网上预 ...

最新文章

  1. ios .a文件支持结构合并arm64 armv7 i386 x86_64
  2. 移动端H5页面高清多屏适配方案
  3. 淘宝架构师为你揭秘2017双十一分布式缓存服务Tair
  4. css的一些常见问题处理方法
  5. thinkpad重装系统不引导_4个步骤,轻松解决电脑重装系统【蓝屏】
  6. conda 升级_jupyter notebook升级体验!笔记本神器—Jupyter Lab
  7. UiAutomator喷射事件的源代码分析
  8. NATS_11:NATS集群构建与验证
  9. 【心电信号】基于matlab GUI心电信号数字滤波处理【含Matlab源码 484期】
  10. 服务端(Win server2012)+IIS管理器配置PHP服务器并部署网站讲解
  11. C语言 一元多项式求导
  12. QT控件被其他控件遮盖
  13. 2014年大数据解决方案提供商面临三大挑战
  14. 腾讯视频会议真实内部实现分享
  15. Android辅助功能 Accessibility Services基本用法笔记
  16. 阻止点击冒泡的解决方法
  17. [svn] TortoisSVN的Blam功能
  18. 服务数据对象简介(Java 环境中的下一代数据编程)
  19. t-sne算法用于处理词嵌入中的高维降维问题
  20. iOS中设置百度地图自定义标注图片,自定义泡泡

热门文章

  1. 上海交通大学计算机学院拟录取,2021年上海交通大学第0001号本科新生录取通知书今发出,首批收到的是强基计划新生...
  2. 手机云便签App敬业签怎么使用同步功能修复异常数据?
  3. 群晖docker下安装mysql
  4. RecyclerView实现Item可拖拽(拖动、删除)
  5. 网站建设说明书(不断具体中……)
  6. C语言入门——计算n的阶乘
  7. Latex 公式换行问题(换行,等号对齐)
  8. 基于Vite + Vue3 + Typescript 实现在线聊天项目
  9. 在线文本编辑器(二)—FCKedit
  10. 遥感识别3——遥感图像数据集大全