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. 【免费软件测试视频-0016】——LR系列之---协议的选择
  2. 数据结构: 插值查找算法
  3. Android逆向工程 初篇
  4. 【bzoj4009】[HNOI2015]接水果 DFS序+树上倍增+整体二分+树状数组
  5. HDU - 3333 Turing Tree(线段树+离线处理)
  6. dede rss.php,DeDeCMS dede 织梦cms RSS全站静态输出的实现方法
  7. 2017年计算机三级网络技术试题,2017年计算机三级网络技术考前试题及答案(8)
  8. C++中的数组与指针
  9. 充值加油卡骗局:一次伪金融诈骗为何能圈数亿
  10. 浏览器端的九种缓存机制介绍
  11. zabbix监控jmx
  12. mui 怎么调用系统键盘_电脑开机关机的几种方法,计算机电源键鼠标键盘网络唤醒图文教程...
  13. Matlab图形窗口大小的控制 ,plot窗口大小,figure大小,axis设置
  14. 二元函数求导公式_基本函数求导公式
  15. sam格式的结构和意义_NGS数据格式02-SAM/BAM最详细解读
  16. Mobile GMaps - Google Map移动版
  17. 四、DNS设置转发器
  18. WebRTC视频JitterBuffer详解
  19. 华为鸿蒙无人驾驶,特斯拉最大的对手竟是华为?Hicar+鸿蒙OS无人驾驶技术不再一家独大!...
  20. 哈工大804电磁场与电磁波考试大纲

热门文章

  1. Eigen矩阵运算库快速上手
  2. 你是如何理解流量池思维的?
  3. 第3章 SQL 习题 - 3.4
  4. CheckedListBox拖拽或者拖动选项
  5. 二次函数顶点式计算机,二次函数顶点式是什么?
  6. 自从有了这套近4000页的开发文档后,Java面试路上就像开了挂一样
  7. Day12--介绍搜索功能并创建serach分支
  8. 中科院自动化所张家俊:DL4MT的Review
  9. STM32F407单片机通用24CXXX读写程序(KEIL),兼容24C系列存储器(24C01到24C512),支持存储器任意地址跨页连续读写多个页
  10. C# Winfrom 自定义控件——带图片的TextBox