HDU 3182 Hamburger Magi(状压dp)

深度学习与人工智能在音视频领域的应用
本文探讨了深度学习技术在音视频处理、AR特效、AI音视频处理等领域的应用,包括图像处理、音视频编解码、自然语言处理、区块链、隐私计算等高级技术,展示了这些技术如何推动音视频行业的发展。

Problem Description
In the mysterious forest, there is a group of Magi. Most of them like to eat human beings, so they are called “The Ogre Magi”, but there is an special one whose favorite food is hamburger, having been jeered by the others as “The Hamburger Magi”.
Let’s give The Hamburger Magi a nickname “HamMagi”, HamMagi don’t only love to eat but also to make hamburgers, he makes N hamburgers, and he gives these each hamburger a value as Vi, and each will cost him Ei energy, (He can use in total M energy each day). In addition, some hamburgers can’t be made directly, for example, HamMagi can make a “Big Mac” only if “New Orleams roasted burger combo” and “Mexican twister combo” are all already made. Of course, he will only make each kind of hamburger once within a single day. Now he wants to know the maximal total value he can get after the whole day’s hard work, but he is too tired so this is your task now!
 

Input
The first line consists of an integer C(C<=50), indicating the number of test cases.
The first line of each case consists of two integers N,E(1<=N<=15,0<=E<=100) , indicating there are N kinds of hamburgers can be made and the initial energy he has.
The second line of each case contains N integers V1,V2…VN, (Vi<=1000)indicating the value of each kind of hamburger.
The third line of each case contains N integers E1,E2…EN, (Ei<=100)indicating the energy each kind of hamburger cost.
Then N lines follow, each line starts with an integer Qi, then Qi integers follow, indicating the hamburgers that making ith hamburger needs.
 

Output
For each line, output an integer indicating the maximum total value HamMagi can get.
 

Sample Input
1 4 90 243 464 307 298 79 58 0 72 3 2 3 4 2 1 4 1 1 0
 

Sample Output
298
 
题意:n个货物,和有的总的钱,然后每一个物体的价值,然后n个物体的花费,然后,是每拿第i种物品时必须已经有的物品


思路:状压dp




#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 1005

int dp[1<<17],ss[1<<16];
int cost[N],va[N];
int n,all,ca[1<<16];

void solve()
{
	int i,j;

	mem(ss,0);

	mem(dp,-1);
	dp[0]=0;

	int len=1<<n;

	int cur;

	fre(cur,0,len)
	{

		if(dp[cur]==-1) continue;

		fre(j,1,n+1)
			{
				if(cur&(1<<(j-1))) continue;

				int to;

				if((cur&ca[j])!=ca[j]) continue;

				to=cur|(1<<(j-1));

				if(dp[cur]+va[j]>dp[to]&&ss[cur]+cost[j]<=all)   //可以更优的到达to,并且花的钱不超过all
				{
					dp[to]=dp[cur]+va[j];
					ss[to]=ss[cur]+cost[j];
				}

			}

	}
	int ans=0;
	fre(cur,0,len)
	   ans=max(ans,dp[cur]);

	pf("%d\n",ans);

}

int main()
{
	int t,i,j;
	sf(t);
	while(t--)
	{
		sff(n,all);

		fre(i,1,n+1)
		  sf(va[i]);

		fre(i,1,n+1)
		  sf(cost[i]);

		mem(ca,0);

		int x,k;


		fre(i,1,n+1)
		{
			sf(k);
			while(k--)
			{
				sf(x);
				ca[i]=ca[i]|(1<<(x-1));
			}
		}

		solve();

	}
   return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值