hdu 6772 Lead of Wisdom ###K ###K //K

题目链接: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 =2e5+10;
 6 const int mod=998244353;
 7 
 8 struct ac
 9 {
10     int a,b,c,d;
11 };
12 vector<ac>E[110];
13 
14 ll ans=1e8;
15 int tot;
16 
17 
18 void dfs(int a,int b,int c,int d,int step)
19 {
20 
21     if(step==tot+1)
22     {
23         ans=max(ans,1ll*a*b*c*d);
24         return;
25     }
26     for(int j=0;j<E[step].size();j++)
27     {
28         int va=E[step][j].a;
29         int vb=E[step][j].b;
30         int vc=E[step][j].c;
31         int vd=E[step][j].d;
32         dfs(a+va,b+vb,c+vc,d+vd,step+1);
33     }
34 
35 }
36 
37 
38 
39 int main()
40 {
41     ios::sync_with_stdio(false);
42     cin.tie(0);
43     int q;
44     cin>>q;
45     while(q--)
46     {
47         int n,k;
48         cin>>n>>k;
49         ans=1e8;
50         map<int,int>f;
51         for(int i=1;i<=100;i++)
52             E[i].clear();
53         tot=0;
54         for(int i=1;i<=n;i++)
55         {
56             ac a;
57             int t;
58             cin>>t;
59             cin>>a.a>>a.b>>a.c>>a.d;
60             if(!f[t])
61                 f[t]=++tot;
62             E[f[t]].pb(a);
63         }
64         dfs(100,100,100,100,1);
65         cout<<ans<<'\n';
66 
67     }
68 
69 
70 }
View Code

 

posted @ 2020-07-28 18:25  canwinfor  阅读(165)  评论(0)    收藏  举报