2020hdu多校第二场 6772 J-Lead of Wisdom【预处理+dfs】

目录

  • 题意
  • 解题思路
  • 代码

题意

  • 链接:Lead of Wisdom
  • 给出n个物品,每种物品有一个种类t,四个属性a,b,c,d,每个种类最多选一件物品,求下式的最大值
    ( 100 + ∑ a i ) ( 100 + ∑ b i ) ( 100 + ∑ c i ) ( 100 + ∑ d i ) \displaystyle \left( 100 + \sum_{} a_i\right) \left(100 + \sum_{} b_i \right)\left(100 + \sum_{} c_i\right)\left(100 + \sum_{} d_i\right) (100+ai)(100+bi)(100+ci)(100+di)

解题思路

  • 暴搜,预处理出每个数量为0的种类的下一个是哪个种类
    2020hdu多校第二场 6772 J-Lead of Wisdom【预处理+dfs】_第1张图片

代码

#include
#include
using namespace std;
typedef long long ll;
const int N=55;
ll ans,n,k,arr[N][N][5],cnt[N],nex[N];
void dfs(ll t,ll a,ll b,ll c,ll d)
{
	if(t==k+1)
	{
		ll tmp=1ll*a*b*c*d;
		ans=max(ans,tmp);
		return;
	}
	if(cnt[t]==0)
	{
		dfs(nex[t],a,b,c,d);
		return;
	}
	for(ll i=1;i<=cnt[t];i++)
		dfs(t+1,a+arr[t][i][0],b+arr[t][i][1],c+arr[t][i][2],d+arr[t][i][3]);
}
int main()
{
	int T;
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%lld",&n,&k);
		ll t;
		for(int i=0;i<=k+1;i++)cnt[i]=0;
		for(ll i=0;i<n;i++)
		{
			scanf("%lld",&t);
			cnt[t]++;
			for(int i=0;i<4;i++)
			scanf("%lld",&arr[t][cnt[t]][i]);
		}
		ll x=k+1;
		for(ll i=x;i>=1;i--)
		{
			nex[i]=x;
			if(cnt[i]>0)x=i;
		}
		ans=100*100*100*100;
		dfs(1,100,100,100,100);
		printf("%lld\n",ans);
	}
	return 0;
} 

你可能感兴趣的:(#,7.23第二场)