2019 ICPC银川区域赛 Girls Band Party(分组背包)

2024-04-16 01:38

本文主要是介绍2019 ICPC银川区域赛 Girls Band Party(分组背包),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

You are currently playing a game called “Garupa”. In an event of the game, you are trying to get more event points. You have nn cards, each with its own name, color, and power. When you play the game, you can put five cards of different names into your deck. The base point of this event is the sum of the power of the cards in your deck. On top of that, the event publishes a color and five names as bonus attributes, which means that each time you have a card with a bonus color in the deck, you end up with a 20%20% increase in event point. And each time you have a card with a bonus name in the deck, you will eventually get 10%10% of the event point (bonus values are calculated by addition, and we round down when calculating the final event point). Please find the maximum event point you will eventually get.

Input
The first line is an integer T~(1 \leq T \leq 50T (1≤T≤50), which is the number of test cases.

For each set of input data, input a positive integer n~(5 \leq n \leq 100000)n (5≤n≤100000) in the first line to indicate the number of cards you have.

The next nn lines, the ii-th line input two strings name_iname
i

, color_icolor
i

and a positive integer power_i~(1 \leq power_i \leq 50000)power
i

(1≤power
i

≤50000) separated by spaces, indicating the name, color, and power of the ii-th card. The input data ensures that there are at least five cards with different names.

The next line input five strings representing the five bonus names. The input data guarantees that the bonus names are different.

The last line input a string representing a bonus color.

The input data ensures that all strings consist of only uppercase and lowercase letters and the max length of them is 1010, and the sum of nn in all sets of input data does not exceed 15000001500000.

Output
For each set of data, output only one line of a positive integer, indicating the maximum number of bonus points that you will eventually get.

样例输入复制
1
6
Saaya Power 45000
Kokoro Happy 45000
Kasumi Cool 45000
Rimi Power 45000
Aya Pure 45000
Aya Power 2000
Saaya Tae Kasumi Rimi Arisa
Power
样例输出复制
382500

题意:
每个物品有3个属性:名称 颜色 价值。
选中特定的名称会是总价值提升0.1倍,选中特定颜色会使总价值提升0.2倍
选5个不同名称物品使得价值和最大

思路:
状态很明显,就是选了多少个数字和提升了多少个0.1倍。将名称相同的物品放在一起,分组背包就好了。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
#include <vector>using namespace std;const int maxn = 1e5 + 7;map<string,int>mp1,mp2;
int dp[maxn][6][16];struct Node
{int val,num;string name,color;bool operator < (const Node&rhs)const{return name < rhs.name;}
}a[maxn];vector<Node>G[maxn];void init(int n)
{memset(dp,-1,sizeof(dp));mp1.clear();mp2.clear();for(int i = 1;i <= n;i++)G[i].clear();
}int main()
{int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);init(n);for(int i = 1;i <= n;i++){cin >> a[i].name >> a[i].color >> a[i].val;}string tmp;for(int i = 1;i <= 5;i++){cin >> tmp;mp1[tmp] = 1;}cin >> tmp;mp2[tmp] = 2;sort(a + 1,a + 1 + n);int cnt = 0;for(int i = 1;i <= n;i++){if(a[i].name != a[i - 1].name){cnt++;}a[i].num = mp1[a[i].name] + mp2[a[i].color];G[cnt].push_back(a[i]);
//            cout << a[i].name << ' ' << a[i].color << ' ' << a[i].num << ' ' << a[i].val << endl;}dp[0][0][0] = 0;for(int i = 1;i <= cnt;i++){for(int k = 0;k <= 5;k++){for(int q = 0;q <= 15;q++){dp[i][k][q] = dp[i - 1][k][q];}}for(int j = 0;j < G[i].size();j++){int val = G[i][j].val,num = G[i][j].num;for(int k = 1;k <= 5;k++){for(int q = num;q <= 15;q++){if(dp[i - 1][k - 1][q - num] != -1){dp[i][k][q] = max(dp[i][k][q],dp[i - 1][k - 1][q - num] + val);}}}}}int ans = 0;for(int i = 0;i <= 5;i++){for(int j = 0;j <= 15;j++){ans = max(ans,dp[cnt][i][j] * (10 + j) / 10);}}printf("%d\n",ans);}return 0;
}

这篇关于2019 ICPC银川区域赛 Girls Band Party(分组背包)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/907484

相关文章

Java反射实现多属性去重与分组功能

《Java反射实现多属性去重与分组功能》在Java开发中,​​List是一种非常常用的数据结构,通常我们会遇到这样的问题:如何处理​​List​​​中的相同字段?无论是去重还是分组,合理的操作可以提高... 目录一、开发环境与基础组件准备1.环境配置:2. 代码结构说明:二、基础反射工具:BeanUtils

Java内存区域与内存溢出异常的详细探讨

《Java内存区域与内存溢出异常的详细探讨》:本文主要介绍Java内存区域与内存溢出异常的相关资料,分析异常原因并提供解决策略,如参数调整、代码优化等,帮助开发者排查内存问题,需要的朋友可以参考下... 目录一、引言二、Java 运行时数据区域(一)程序计数器(二)Java 虚拟机栈(三)本地方法栈(四)J

Java如何根据文件名前缀自动分组图片文件

《Java如何根据文件名前缀自动分组图片文件》一大堆文件(比如图片)堆在一个目录下,它们的命名规则遵循一定的格式,混在一起很难管理,所以本文小编就和大家介绍一下如何使用Java根据文件名前缀自动分组图... 目录需求背景分析思路实现代码输出结果知识扩展需求一大堆文件(比如图片)堆在一个目录下,它们的命名规

MySQL中的分组和多表连接详解

《MySQL中的分组和多表连接详解》:本文主要介绍MySQL中的分组和多表连接的相关操作,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录mysql中的分组和多表连接一、MySQL的分组(group javascriptby )二、多表连接(表连接会产生大量的数据垃圾)MySQL中的

SpringValidation数据校验之约束注解与分组校验方式

《SpringValidation数据校验之约束注解与分组校验方式》本文将深入探讨SpringValidation的核心功能,帮助开发者掌握约束注解的使用技巧和分组校验的高级应用,从而构建更加健壮和可... 目录引言一、Spring Validation基础架构1.1 jsR-380标准与Spring整合1

Mysql如何将数据按照年月分组的统计

《Mysql如何将数据按照年月分组的统计》:本文主要介绍Mysql如何将数据按照年月分组的统计方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql将数据按照年月分组的统计要的效果方案总结Mysql将数据按照年月分组的统计要的效果方案① 使用 DA

使用Python在Excel中创建和取消数据分组

《使用Python在Excel中创建和取消数据分组》Excel中的分组是一种通过添加层级结构将相邻行或列组织在一起的功能,当分组完成后,用户可以通过折叠或展开数据组来简化数据视图,这篇博客将介绍如何使... 目录引言使用工具python在Excel中创建行和列分组Python在Excel中创建嵌套分组Pyt

使用C#如何创建人名或其他物体随机分组

《使用C#如何创建人名或其他物体随机分组》文章描述了一个随机分配人员到多个团队的代码示例,包括将人员列表随机化并根据组数分配到不同组,最后按组号排序显示结果... 目录C#创建人名或其他物体随机分组此示例使用以下代码将人员分配到组代码首先将lstPeople ListBox总结C#创建人名或其他物体随机分组

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

poj2576(二维背包)

题意:n个人分成两组,两组人数只差小于1 , 并且体重只差最小 对于人数要求恰好装满,对于体重要求尽量多,一开始没做出来,看了下解题,按照自己的感觉写,然后a了 状态转移方程:dp[i][j] = max(dp[i][j],dp[i-1][j-c[k]]+c[k]);其中i表示人数,j表示背包容量,k表示输入的体重的 代码如下: #include<iostream>#include<