当前位置:网站首页>Niuke real problem programming - day14
Niuke real problem programming - day14
2022-07-07 14:52:00 【weixin_ forty-five million seven hundred and fifty thousand fou】
Programming environment :c++
1、 String value
describe : There is an interesting way to calculate the value of strings : Count the number of occurrences of each character in the string , Then find the sum of the squares of the number of all characters as the value of the string
for example : character string "abacaba", includes 4 individual 'a',2 individual 'b',1 individual 'c', So the value of this string is 4 * 4 + 2 * 2 + 1 * 1 = 21
Niuniu has a string s, And allow you to start from s Remove up to k Characters , Your goal is to minimize the value of the resulting string .
Algorithmic thought :
According to the title requirements , To remove the fixed number of characters , Strings are the least valuable , Then each time you remove the character that appears the most times in the current string . First, count the number of characters in the string , After removing one at a time , You need to reorder the array that counts the number of character occurrences , Make sure that each overflow is the string with the most occurrences . Finally, according to the string value formula , Calculate the minimum value of the final string .
Part of the code implementation :
2、 Under the kitchen
describe :
Niuniu wants to try some new dishes , Each dish needs some different materials , Ask how many different materials need to be prepared to complete all the dishes .
Input description : Each input contains 1 Test cases . The... Of each test case i That's ok , To complete the first i What materials are needed for this dish , Each material is separated by a space , The input contains only uppercase letters and spaces , Input files do not exceed 50 That's ok , No more than... Per line 50 Characters .
Algorithmic thought :
The number of lines entered in the title is uncertain , You need to decide whether there is any string input , Here I omit the concept of line , Store all the ingredients you need into a string array . For all ingredients , We need to de duplicate it , Get the number of ingredients you need to prepare . First, sort all strings , Then the same ingredients will come together , Traverse the sorted string array , When adjacent elements are different , It represents different ingredients ( Count +1). The number of ingredients required after weight removal is obtained after traversal .
3、 Asset package packaging
describe :
In financial asset transactions , It often involves the selection and packaging of asset packages . In the process of asset package packaging , Each type of asset has a fixed quantity and value , You need to select some assets to package , Maximize the total value of the asset package . When packaging, each asset can only be packaged as a whole , Indivisible . It is assumed that the existing can accommodate M Asset package of assets , In addition, there are N Types of assets . assets Na The number of Ta strip , The total value is Va element ; assets Nb The number of Tb strip , The total value is Vb element ; assets Nc The number of Tc strip , The total value is Vc element ......; assets Nn The number of Tn, The total value is Vn. Write algorithms , Choosing which types of assets to put into the asset package can maximize the total value of the asset package ?
Algorithmic thought :
Because the asset package can only be placed as a whole or not , So the topic is actually a 0/1 Dynamic programming of knapsack . set up j Is the total capacity ,wi For the first time i The weight of each item . If the total capacity of the backpack j Less than i Space occupied by items , The maximum value that can be obtained at this time is equivalent to considering 1 To the first i-1 The total storage capacity of items is j The backpack . otherwise , You can choose to put it or not i Item : If you don't put the first i Item , At this time, the maximum value and only put the front i-1 Same piece ; The first i When items are put into the backpack , The total capacity is j Your backpack must be allocated wi Space for i Item , And before the first 1 To the first i-1 Items can only be placed with a total capacity of j-wi In my backpack , The greater of the two cases . Initialize a result array dp, There's recursion :dp(i,j)=max {dp(i-1, j),dp(i-1, j-w)+vi}
The code part implements :
边栏推荐
- 【历史上的今天】7 月 7 日:C# 发布;Chrome OS 问世;《仙剑奇侠传》发行
- PAG experience: complete AE dynamic deployment and launch all platforms in ten minutes!
- Internal sort - insert sort
- 2022云顾问技术系列之高可用专场分享会
- Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
- Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
- asp. Netnba information management system VS development SQLSERVER database web structure c programming computer web page source code project detailed design
- 关于后台动态模板添加内容的总结 Builder使用
- JS image to Base64
- 智汀不用Home Assistant让小米智能家居接入HomeKit
猜你喜欢
Data Lake (IX): Iceberg features and data types
C 6.0 language specification approved
EfficientNet模型的完整细节
How bad can a programmer be? Nima, they are all talents
多商戶商城系統功能拆解01講-產品架構
Notes de l'imprimante substance: paramètres pour les affichages Multi - écrans et multi - Résolutions
一个程序员的水平能差到什么程度?尼玛,都是人才呀...
Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
CPU与chiplet技术杂谈
大厂做开源的五大痛点
随机推荐
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
防火墙基础之服务器区的防护策略
Decrypt the three dimensional design of the game
EMQX 5.0 发布:单集群支持 1 亿 MQTT 连接的开源物联网消息服务器
【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
Webrtc audio anti weak network technology (Part 1)
多商戶商城系統功能拆解01講-產品架構
KITTI数据集简介与使用
MicTR01 Tester 振弦采集模块开发套件使用说明
Substance Painter笔记:多显示器且多分辨率显示器时的设置
PyTorch模型训练实战技巧,突破速度瓶颈
buffer overflow protection
15、文本编辑工具VIM使用
WebRTC 音频抗弱网技术(上)
EfficientNet模型的完整细节
上半年晋升 P8 成功,还买了别墅!
Andriod --- JetPack :LiveData setValue 和 postValue 的区别
潘多拉 IOT 开发板学习(HAL 库)—— 实验12 RTC实时时钟实验(学习笔记)
Ascend 910 realizes tensorflow1.15 to realize the Minist handwritten digit recognition of lenet network
2022 cloud consulting technology series high availability special sharing meeting