codeforces 1042 B. Vitamins(暴力)
Berland shop sells nn kinds of juices. Each juice has its price cici. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin “A”, vitamin “B” and vitamin “C”. Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer nn (1≤n≤1000)(1≤n≤1000) — the number of juices.
Each of the next nn lines contains an integer cici (1≤ci≤100000)(1≤ci≤100000) and a string sisi — the price of the ii-th juice and the vitamins it contains. String sisi contains from 11to 33 characters, and the only possible characters are “A”, “B” and “C”. It is guaranteed that each letter appears no more than once in each string sisi. The order of letters in strings sisi is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5+6+4=155+6+4=15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 1616, which isn’t optimal.
In the second example Petya can’t obtain all three vitamins, as no juice contains vitamin “C”.
!
题目很简单,就是给你 ,N瓶果汁,每瓶有不同的维生素和对应价格,问你 需要ABC维生素的最小价值,一开始没想到可以直接暴力… 然后看了一下运行时间,想了想暴力枚举所有情况就行了
#include<bits/stdc++.h>
#define fi first
#define se second
#define FOR(a) for(int i=0;i<a;i++)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> LP;
const ll inf=0x3f3f3f3f;
const int N=2e6;
const ll mod=1e9+7;
map<string,ll> mp;
map<string ,int>ml;
ll n,m,k,a[N],b[N],f[N];
int did[N],vis[N],num[N];
string s,ss;
ll s1,s2,s3,s4=0,flag,tot,t,sum,pos, cnt,x,y,xx,yy,ans;
vector<ll> v;
//char v[150][150];
set<int> se;
//P a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
mp["A"]=inf;
mp["B"]=inf;
mp["C"]=inf;
mp["AB"]=inf;
mp["AC"]=inf;
mp["BC"]=inf;
mp["ABC"]=inf;
for(int i=0;i<n;i++)
{
cin>>m;
cin>>s;
sort(s.begin(),s.end());
mp[s]=min(mp[s],m);
}
ll ans=inf;
ans=min(mp["A"]+mp["B"]+mp["C"],ans);
ans=min(mp["A"]+mp["BC"],ans);
ans=min(mp["B"]+mp["AC"],ans);
ans=min(mp["C"]+mp["AB"],ans);
ans=min(mp["AB"]+mp["AC"],ans);
ans=min(mp["AB"]+mp["BC"],ans);
ans=min(mp["AC"]+mp["BC"],ans);
ans=min(mp["ABC"],ans);
if(ans>=inf) ans=-1;
cout<<ans<<endl;
}