首页 > 其他 > 详细

hdu 6772 Lead of Wisdom

时间:2020-07-28 21:29:41      阅读:49      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6772

题意:给定n个物品,每个物品 有种类t  还有属性a b c d  每种种类的物品最多穿一种

问最大的公式值DMG为多少  技术分享图片

 

考虑到数据范围  还有题目给的时间8000ms  直接考虑暴力dfs   时间复杂度最坏大概是10*3^16*2=8*10^8 左右   

但是由于给的种类是离散的, 如果 没有处理成连续的话, 时间复杂度可能还要乘上n  这样会TLE 处理成连续的即可

技术分享图片
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 #define pb push_back
 5 const int maxn =1e5+10;
 6 const int mod=1e9+7;
 7 int n,k;
 8 vector<int>E[55];
 9 int nxt[55];
10 
11 ll ans=0;
12 
13 
14 void dfs(int t,int a,int b,int c,int d)
15 {
16     int u=nxt[t];
17     if(u==100)
18     {
19         ll sum=1ll*(100+a)*(100+b)*(100+c)*(100+d);
20         ans=max(ans,sum);
21         return;
22     }
23     int len=E[u].size();
24     for(int i=0;i*4<len;i++)
25     {
26         int ta=a+E[u][0+i*4];
27         int tb=b+E[u][1+i*4];
28         int tc=c+E[u][2+i*4];
29         int td=d+E[u][3+i*4];
30         dfs(t+1,ta,tb,tc,td);
31     }
32 
33 }
34 void init()
35 {
36     for(int i=1;i<=50;i++)
37         E[i].clear();
38     memset(nxt,0,sizeof(nxt));
39     ans=0;
40 }
41 
42 set<int>s;
43 
44 int main()
45 {
46     ios::sync_with_stdio(false);
47     cin.tie(0);
48     int t;
49     cin>>t;
50     while(t--)
51     {
52         cin>>n>>k;
53         set<int>s;
54         init();
55         for(int i=1;i<=n;i++)
56         {
57             int t,a,b,c,d;
58             cin>>t>>a>>b>>c>>d;
59             s.insert(t);
60             E[t].pb(a);
61             E[t].pb(b);
62             E[t].pb(c);
63             E[t].pb(d);
64         }
65         int tot=0;
66         for(auto &v:s)
67         {
68             nxt[++tot]=v;
69         }
70         nxt[++tot]=100;
71         dfs(1,0,0,0,0);
72         cout<<ans<<\n;
73 
74 
75     }
76 
77 }
View Code

 

hdu 6772 Lead of Wisdom

原文:https://www.cnblogs.com/winfor/p/13392950.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!