题目描述:原题链接
You are given three multisets of pairs of colored sticks:
R pairs of red sticks, the first pair has length r1, the second pair has length r2, …, the R-th pair has length rR;
G pairs of green sticks, the first pair has length g1, the second pair has length g2, …, the G-th pair has length gG;
B pairs of blue sticks, the first pair has length b1, the second pair has length b2, …, the B-th pair has length bB;
You are constructing rectangles from these pairs of sticks with the following process:
take a pair of sticks of one color;
take a pair of sticks of another color different from the first one;
add the area of the resulting rectangle to the total area.
Thus, you get such rectangles that their opposite sides are the same color and their adjacent sides are not the same color.
Each pair of sticks can be used at most once, some pairs can be left unused. You are not allowed to split a pair into independent sticks.
What is the maximum area you can achieve?
Input
The first line contains three integers R, G, B (1≤R,G,B≤200) — the number of pairs of red sticks, the number of pairs of green sticks and the number of pairs of blue sticks.
The second line contains R integers r1,r2,…,rR (1≤ri≤2000) — the lengths of sticks in each pair of red sticks.
The third line contains G integers g1,g2,…,gG (1≤gi≤2000) — the lengths of sticks in each pair of green sticks.
The fourth line contains B integers b1,b2,…,bB (1≤bi≤2000) — the lengths of sticks in each pair of blue sticks.
Output
Print the maximum possible total area of the constructed rectangles.
Examples
input
1 1 1
3
5
4
output
20
input
2 1 3
9 5
1
2 8 5
output
99
input
10 1 1
11 7 20 15 19 14 2 4 13 14
8
11
output
372
思路:
先将每颜色的长度从大到小排序,后3重循环暴力枚举出答案。因为n只有200。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=230;
ll r[N],g[N],b[N];
ll dp[N][N][N];
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
int R,G,B; scanf("%d %d %d",&R,&G,&B);
for(int i=1;i<=R;i++) scanf("%lld",&r[i]);
for(int i=1;i<=G;i++) scanf("%lld",&g[i]);
for(int i=1;i<=B;i++) scanf("%lld",&b[i]);
sort(r+1,r+R+1,cmp);
sort(g+1,g+G+1,cmp);
sort(b+1,b+B+1,cmp);
ll res=0;
for(int i=1;i<=R+1;i++)
{
for(int j=1;j<=G+1;j++)
{
for(int k=1;k<=B+1;k++)
{
dp[i][j][k]=max(max(dp[i][j][k],dp[i][j-1][k-1]+g[j-1]*b[k-1]),
max(dp[i-1][j-1][k]+r[i-1]*g[j-1],dp[i-1][j][k-1]+r[i-1]*b[k-1]));
res=max(res,dp[i][j][k]);
}
}
}
printf("%lld\n",res);
return 0;
}