关闭

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

1079人阅读 评论(0) 收藏 举报

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;
}


 

0
0
查看评论

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

Super Phyllis Time Limit: 1000MS    Memory limit: 65536K 题目描述 Phyllis works for a large, multi-national corporation. She mov...
  • kkkwjx
  • kkkwjx
  • 2013-12-02 16:10
  • 1599

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

Time Limit: 1000MS    Memory limit: 65536K 题目描述 Years before Candy Crush became the wildly popular game that may lead developer ...
  • kkkwjx
  • kkkwjx
  • 2013-12-01 12:50
  • 1716

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

Playing Fair with Cryptography Time Limit: 1000MS    Memory limit: 65536K 题目描述 Encryption is the process of taking plaintext a...
  • kkkwjx
  • kkkwjx
  • 2013-12-01 15:01
  • 1701

中国海洋大学各个校区都有什么专业

https://zhidao.baidu.com/question/355495551.html
  • xiyangyang8110
  • xiyangyang8110
  • 2017-12-19 14:55
  • 104

第四届“图灵杯”NEUQ-ACM程序设计竞赛(团队赛)-网络同步赛D 分形

问题 D: 简单的图形输出 时间限制: 1 Sec 内存限制: 30 MB 提交: 526 解决: 103 [提交][状态][讨论版] 题目描述 谢尔宾斯基三角形是一种分形,它的构造过程是这样的: 1.取一个实心的三角形。(多数使用等边三角形) 2.沿三边中点的连线,将它分成四个小...
  • qq_33183401
  • qq_33183401
  • 2017-06-14 21:17
  • 303

第四届“图灵杯”NEUQ-ACM程序设计竞赛(团队赛)-网络同步赛B(排序)

问题 B: 一个简单的问题 时间限制: 1 Sec 内存限制: 64 MB 提交: 619 解决: 434 [提交][状态][讨论版] 题目描述 实验班最近在准备购置新的书籍。现在统计出了一份有十本书的书单,但是由于预算有限,必须删掉一本书。大家讨论决定把价格第三高的书删掉,请你找出这...
  • qq_33183401
  • qq_33183401
  • 2017-06-11 16:22
  • 192

图灵杯-第四届“图灵杯”NEUQ-ACM 程序设计竞赛-D-简单图形输出

ACM模版描述 题解谢尔宾斯基三角形,有趣的问题,图形打印,根据前一个状态拼接出来下一个状态,样例可以发现,这里相当于下边是两个前一个状态的三角形并列,上边是前一个状态的三角形居中。注意补空格!这个问题内存比较吃紧,所以一开始 WA、MLE 了几发,忽略了很重要的一点,虽然这个看起来是等边三角形,...
  • f_zyj
  • f_zyj
  • 2017-06-12 01:03
  • 295

2013第四届 蓝桥杯c/c++B组预赛 解题报告

大半部分题目都是自己做的,可能还有存在错误的地方,还望各位指正。 有不会的题目,还请大牛们留下解题思路,谢谢了。   第一题:高斯日记     大数学家高斯有个好习惯:无论如何都要记日记。他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代...
  • u010829118
  • u010829118
  • 2013-11-25 18:40
  • 1122

哈理工OJ 2074 逃生(广搜题目)

逃生 Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 94(28 users) Total Accepted: 24(20 users) Rating: Special Judge: No Description ...
  • qq_32866009
  • qq_32866009
  • 2016-04-07 14:53
  • 601

2016年中国智慧杯——助学金大赛

2016年中国智慧杯开始于2016.11,在2017.2结束。其中有三个比赛方向:交通赛,贷款,助学金。由于是第一次参赛,对Python也是因为这个比赛的示例代码才入门的,交通赛数据量太大搞不了,贷款觉得对业务估计不是很懂,就选择了助学金赛。
  • u012067933
  • u012067933
  • 2017-04-29 16:29
  • 164
    个人资料
    • 访问:230262次
    • 积分:6083
    • 等级:
    • 排名:第4909名
    • 原创:394篇
    • 转载:10篇
    • 译文:0篇
    • 评论:3条
    最新评论