zoukankan      html  css  js  c++  java
  • HDU6672 Lead of Wisdom(爆搜)

    Lead of Wisdom

    In an online game, "Lead of Wisdom" is a place where the lucky player can randomly get powerful items.

    img

    There are k types of items, a player can wear at most one item for each type. For the i

    -th item, it has four attributes (a_i,b_i,c_i)

    and (d_i). Assume the set of items that the player wearing is S

    , the damage rate of the player DMG

    can be calculated by the formula:

    (DMG=(100+Sigma a_i)(100+Sigma b_i)(100+Sigma c_i)(100+Sigma d_i))

    Little Q has got n

    items from "Lead of Wisdom", please write a program to help him select which items to wear such that the value of DMG is maximized.

    Input

    The first line of the input contains a single integer T

    (1≤T≤10), the number of test cases.

    For each case, the first line of the input contains two integers n

    and k (1≤n,k≤50), denoting the number of items and the number of item types.

    Each of the following n lines contains five integers (t_i*,*a_i,b_i,c_i, d_i)

    $ (1≤t_i≤k,0≤a_i,b_i,c_i,d_i≤100)$, denoting an item of type (t_i)

    whose attributes are $a_i,b_i,c_i $and (d_i)

    .

    Output

    For each test case, output a single line containing an integer, the maximum value of DMG

    .

    Sample Input

    1
    6 4
    1 17 25 10 0
    2 0 0 25 14
    4 17 0 21 0
    1 5 22 0 10
    2 0 16 20 0
    4 37 0 0 0
    

    Sample Output

    297882000
    

    暴力签到,对于这个数据规模直接爆搜即可,复杂度证明。可以用数组模拟一下链表,跳过没用的组。

    当时没做出来,反思一下:当时写A有点怀疑人生,加上队友告诉我是个DP,加上判断题目类型的能力很弱....其实还是自己辣鸡T^T

    这题本地跑了14s一度以为哪里出问题了,没想到交上去过了2333

    #include <bits/stdc++.h>
    using namespace std;
    struct item
    {
    	long long a, b, c, d;
    };
    vector<vector<item> > v;
    int n, k;
    long long ans = -1e18;
    int Next[55];
    void dfs(int x, long long a, long long b, long long c, long long d)
    {
    	if(x == -1)
    	{
    		long long sum = a * b * c * d;
    		ans = max(ans, sum);
    		return;
    	}
    	for(int i = 0; i < v[x].size(); i++)
    	{
    		dfs(Next[x], a + v[x][i].a, b + v[x][i].b, c + v[x][i].c, d + v[x][i].d);
    	}
    }
    int main()
    {
    	//freopen("1010.in","r",stdin);
    	//freopen("myout.out","w",stdout);
    	int Case;
    	cin >> Case;
    	for(int i = 1; i <= 51; i++)
    	{
    		vector<item> temp;
    		v.push_back(temp);
    	}
    	while(Case--)
    	{
    		cin >> n >> k;
    		ans = -1e18;
    		set<int>s;
    		//memset(Next, 0, sizeof(Next));
    		long long sa = 100, sb = 100, sc = 100, sd = 100;
    		for(int i = 1; i <= 51; i++)
    		{
    			v[i].clear();
    		}
    		for(int i = 1; i <= n; i++)
    		{
    			int t, a, b, c, d;
    			scanf("%d%d%d%d%d", &t, &a, &b, &c, &d);
    			v[t].push_back(item{a, b, c, d});
    			s.insert(t);
    		}
    		set<int>::iterator it;
    		int start, before;
    		bool began = 0;
    		for(it = s.begin(); it != s.end(); it++)
    		{
    			if(v[*it].size() == 1)
    			{
    				sa += v[*it][0].a;
    				sb += v[*it][0].b;
    				sc += v[*it][0].c;
    				sd += v[*it][0].d;
    			}
    			else if(!began) 
    			{
    				start = before = *it;
    				began = 1;
    			}
    			else 
    			{
    				Next[before] = *it;
    				before = *it;
    			}
    		}
    		Next[before] = -1;
    		dfs(start, sa, sb, sc, sd);
    		cout << ans << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    JSONObject的问题- 在用JSONObject传参到controller接收为空白和JSONArray添加json后转string不正确
    SpringContextHolder使用报错:applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder
    MQ报错Waiting for workers to finish.Stopping container from aborted consumer.Successfully waited for workers to finish.
    nacos的docker启动
    问题总结
    ubuntu docker中文乱码问题
    你该用HTTP2了
    Redis哨兵(Sentinel)模式快速入门
    Redis主从复制的原理
    Redis持久化的原理及优化
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13383597.html
Copyright © 2011-2022 走看看