Distant Pastures

Distant Pastures

暂无测试数据。

题目描述

Farmer John's farm is made up of an N x N grid of pastures, where each pasture contains one of two different types of grass. To specify these two types of grass, we use the characters ( and ), so for example FJ's farm might look like the following grid:
(())
)()(
)(((
))))
When Bessie the cow travels around the farm, it takes her A units of time to move from a pasture to an adjacent pasture (one step north, south, east, or west) with the same grass type, or B units of time to move to an adjacent pasture with a different grass type. Whenever Bessie travels from one pasture to a distant pasture, she always uses a sequence of steps that takes the minimum amount of time. Please compute the greatest amount of time Bessie will ever need to take while traveling between some pair of pastures on the farm.

问题描述
给定一个n×n的一个网格,每个格子有一个字符,要么是’(‘,要么是’)’。每个格子和它的上下左右的四个格子相邻,对于相邻的两个格子x和y,从x走到y的过程中,如果x和y中的字符相同,消耗A单位时间,如果x和y中字符不同,消耗B单位时间。定义点S到点T的时间为D(S,T),现在想请你求出网格中最大的D(S,T)。

输入格式

第一行三个整数n,A,B;
接下来n行描述这个n×n的网格。
1 <= n <= 30,1 <= A <= 1,000,000,1 <= B <= 1,000,000。

输出格式

一个整数,最大的D(S,T)。

样例输入

3 1 2
(((
()(
(()

样例输出

5
 样例说明
左上角到右下角所需的时间为5,是最大值

提示

Silver

信息

难度
(无)
分类
(无)
标签
递交数
0
已通过
0
通过率
?
上传者