The 2022 ICPC Asia Xian Regional Contest-F. Hotel

You are doing volunteer work for a programming competition in an ancient hotel. Unfortunately, the hotel provides no phone signal or tap water since it can be dated back to the Qin Dynasty, and you have to assign the contestants to the hotel rooms manually instead of using the internet apps. Fortunately, the hotel has sufficient rooms, and you have taken a computer that lets you do some computation locally.

There are nn teams, each with exactly 3 contestants. There are 2 types of rooms in the hotel, the single room and double room, which can receive at most 1 and 2 contestants, respectively. To avoid embarrassing contestants, if two contestants are assigned to a double room, they must come from the same team and have the same gender.

The cost of each room of the same type is the same, but different types may have different costs. Your program needs to calculate the minimum price the host has to pay. The teams are waiting in the registration hall now, and the competition finance officer relies on you to save costs and make a fortune by the residual value. Be quick, or the finance officer will sue you for violating his reputation!

Input

The first line of input contains three integers n, c1 and c2 (1≤n,c1,c2≤1000), denoting the number of teams, the cost of a single room and a double room respectively.

In the following n lines, each line contains a string S with exactly 3 uppercase English letters. The letters in a string denote the genders of the contestants in one team and will be represented by A to Z, respecting the diversity of human beings.

Output

The output should contain a single integer, denoting the minimum cost of hotel allocation for contestants.

Examples

input

3 1 3
MMM
MMM
FFF

output

9

input

3 3 1
ABC
DEF
GHI

output

9

input

10 438 438
WWW
SOU
PUN
ETC
OME
CFI
NAL
GOO
DHO
TEL

output

12264

题意:n个队伍要住房,每个队伍三个人(字母表示),有单人间和双人间,费用是c1,c2,不同队伍不能住一个房间,但是,同一个队伍相同字母可以住进同一个双人间,问最小花费。

注意:一个人也可以住双人间

解析:就是分类讨论,不同队伍不能住一个房间,因此我们每输入一个队伍,就算出该队伍的最少花费,累加即可。因为每个队伍三个字母,最多3种情况,1.三个全部相同   2.其中两个相同   3.三个互不相同,然后每个情况所有住房方案花费取个min即可

做的时候可以发现1,2情况房间方案是相同的👻

#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int t,c1,c2,sum=0;
	scanf("%d%d%d",&t,&c1,&c2);
	while(t--)
	{
		string a;
		cin>>a;
		if(a[0]!=a[1]&&a[0]!=a[2]&&a[1]!=a[2]) sum+=min(3*c1,3*c2);//三个互不相同
		else sum+=min({3*c1,c1+c2,2*c2});
	}	//3个单人间,1单1双,2双
	printf("%d\n",sum);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值