POJ1404I-Keyboard题解动态规划DP

『杭电1611』I-Keyboard Problem Description Most of you have probably tried to type an SMS message on the keypad of a cellular phone. It is sometimes very annoying to write longer messages, because one key must be usually pressed several times to produce a single letter. It is 阅读详情
I-Keyboard
Time Limit: 2000MS Memory Limit: 32768K
Total Submissions: 3753 Accepted: 1889

Description

Most of you have probably tried to type an SMS message on the keypad of a cellular phone. It is sometimes very annoying to write longer messages, because one key must be usually pressed several times to produce a single letter. It is due to a low number of keys on the keypad. Typical phone has twelve keys only (and maybe some other control keys that are not used for typing). Moreover, only eight keys are used for typing 26 letters of an English alphabet. The standard assignment of letters on the keypad is shown in the left picture:
1
 
2
abc
3
def
4
ghi
5
jkl
6
mno
7
pqrs
8
tuv
9
wxyz
*
 
0
space
#
 
      
1
 
2
abcd
3
efg
4
hijk
5
lm
6
nopq
7
rs
8
tuv
9
wxyz
*
 
0
space
#
 

There are 3 or 4 letters assigned to each key. If you want the first letter of any group, you press that key once. If you want the second letter, you have to press the key twice. For other letters, the key must be pressed three or four times. The authors of the keyboard did not try to optimise the layout for minimal number of keystrokes. Instead, they preferred the even distribution of letters among the keys. Unfortunately, some letters are more frequent than others. Some of these frequent letters are placed on the third or even fourth place on the standard keyboard. For example, S is a very common letter in an English alphabet, and we need four keystrokes to type it. If the assignment of characters was like in the right picture, the keyboard would be much more comfortable for typing average English texts.

ACM have decided to put an optimised version of the keyboard on its new cellular phone. Now they need a computer program that will find an optimal layout for the given letter frequency. We need to preserve alphabetical order of letters, because the user would be confused if the letters were mixed. But we can assign any number of letters to a single key.

Input

There is a single positive integer T on the first line of input. It stands for the number of test cases to follow. Each test case begins with a line containing two integers K, L (1 <= K <= L <= 90) separated by a single space. K is the number of keys, L is the number of letters to be mapped onto those keys. Then there are two lines. The first one contains exactly K characters each representing a name of one key. The second line contains exactly L characters representing names of letters of an alphabet. Keys and letters are represented by digits, letters (which are case-sensitive), or any punctuation characters (ASCII code between 33 and 126 inclusively). No two keys have the same character, no two letters are the same. However, the name of a letter can be used also as a name for a key.

After those two lines, there are exactly L lines each containing exactly one positive integer F1, F2, ... FL. These numbers determine the frequency of every letter, starting with the first one and continuing with the others sequentially. The higher number means the more common letter. No frequency will be higher than 100000.

Output

Find an optimal keyboard for each test case. Optimal keyboard is such that has the lowest "price" for typing average text. The price is determined as the sum of the prices of each letter. The price of a letter is a product of the letter frequency (Fi) and its position on the key. The order of letters cannot be changed, they must be grouped in the given order.

If there are more solutions with the same price, we will try to maximise the number of letters assigned to the last key, then to the one before the last one etc.

More formally, you are to find a sequence P1, P2, ... P L representing the position of every letter on a particular key. The sequence must meet following conditions:

P1 = 1
for each i>1, either Pi = P i-1+1 or Pi = 1
there are at most K numbers Pi such that Pi = 1
the sum of products SP = F1*P1+F2*P2+...+F L*P L is minimal
for any other sequence Q meeting these criteria and with the same sum SQ = SP, there exists such M, 1 <= M <= L that for any J, M < J <= L, P J = Q J, and P M > Q M.
The output for every test case must start with a single line saying Keypad #I:, where I is a sequential order of the test case, starting with 1. Then there must be exactly K lines, each representing one letter, in the same order that was used in input. Each line must contain the character representing the key, a colon, one space and a list of letters assigned to that particular key. Letters are not separated from each other.

Print one blank line after each test case, including the last one.

Sample Input

1
8 26
23456789
ABCDEFGHIJKLMNOPQRSTUVWXYZ
3371
589
1575
1614
6212
971
773
1904
2989
123
209
1588
1513
2996
3269
1080
121
2726
3083
4368
1334
518
752
427
733
871

Sample Output

Keypad #1:
2: ABCD
3: EFG
4: HIJK
5: LM
6: NOPQ
7: RS
8: TUV
9: WXYZ

Source

有序的划分模型
dp[i][j]表示第j个字母放在第i个键上的最优值
dp[i][j]=min{dp[i-1][k-1]+s[k][j]};i<=k<=j
模糊综合评价模型 一.引子 1.数学归纳法:同高中知识 2.秃子悖论:秃子悖论 这俩个例子都是类似于“量变引起质变”的道理,而在数学中我们把这类问题的性质叫做“模糊性”,在生活中我们也经常能遇到一些模糊的概念,比如年轻、帅、很少很多… 二.概述 模糊综合评价法是一种基于模糊数学的综合评价方法。该综合评价法根据模糊数学的隶属度理论把定性评价转化为定量评价,即用模糊数学对受到多种因素制约的事物或对象做出一个总体的评价。它具有结果清晰,系统性强的特点,能较好地解决模糊的、难以量化的问题,适合各种非确定性问题的解决。——来自百度百 阅读详情

相关推荐

App inventor2通过蓝牙控制Arduino Uno LED开关

App inventer2控制Arduino Uno LED开关 如果学会这个小程序,大部分的手机通过蓝牙控制Arduino的功能都可以实现,这个小示例是通过蓝牙模块向Arduino发送"0"和"1",而其它功能要发送其它不同的字符串内容给Arduino. 所需硬件: Arduino Uno JDY-16 蓝牙模块(我的是蓝牙4.2版本) 草帽LED(可选) 手机(我用的是安卓,苹果手机应该也可以,最近其应用商店也有App inventor(AI)伴侣) 软件: Aduino IDE或者Platfom

Firmin123456的博客 5498

Hoj 1042 I-KeyBoard

Problem Description Most of you have probably tried to type an SMS message on the keypad of a cellular phone. It is sometimes very annoying to write longer messages, because one key must be usually p...

包子不卖包子 400

逆变器技术解析:DDSRF双解耦在正负序分离中的关键作用

本文深入解析了DDSRF双解耦技术在逆变器正负序分离中的关键作用。通过建立正反旋转坐标系并利用交叉反馈解耦网络,DDSRF能快速、精准地分离电网电压中的正负序分量,从而显著提升锁相环在电网不平衡条件下的精度与系统稳定性,是现代高性能并网逆变器的核心算法之一。

m3n5b7v8c9x的博客 410

poj1404题解

来源:http://poj.org/problem?id=1040 思路:dfs 代码:#include <stdio.h> #include <string.h> int z,n,m,s[30],t[30],w[30],e[30],g[8],max; //s,t数组分别记录订单的起点和终点,w数组记录订单的人数,e数组记录订单的利润,g数组记录第i个车站的人数 void dfs(int dep

ME495的博客 494

基于FPGA的DDR学习——1.基础知识

⚪DDR2(Double Data Rate2)SDRAM是由JEDEC(电子设备工程联合委员会)开发的第三代SDRAM内存技术标准,1.8V工作电压,240线接口,提供了相较于DDR SDRAM更高的运行效能与更低的电压,同样采用在时钟的上升/下降沿同时进行数据传输的基本方式,但拥有两倍于上一代DDR内存预读取能力(即4bit数据预取能力),其常见的频率规范有DDR2 400\533\667\800\1066\1333等,总线频率553MHZ的DDR2内存只需133MHZ的工作频率。

qq_44932488的博客 2070

数字后端流程--place

Floorplan完成后芯片的大致框架已经出现,万里长征已经迈出特别重要的第一步了,前面的步骤我们已经完成了io port,macro的摆放,现在core外只剩下std cell(标准单元)了,Place这一步就是要把std cell放进core里。看到密密麻麻的std cell也不用紧张,因为放std cell不用像macro手动一个一个摆,工具就可以帮我们完成大部分工作。虽然这一步的工作只有一个,但也不是只要Place完就能进行下一步的,衡量Place质量是否满足标准会通过以下几点判断。

qq_68400574的博客 771

POJ1410:线段相交

POJ1410 题解:细节很多,需要注意 给出的矩阵左上角和右下角没有必然关系。 线段在矩阵内部也算相交。 规范相交和非规范相交都要考虑。 代码 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath&...

FlyingJack 1124

别再只测电压了!用STM32G474的ADC玩点花的:过采样提升精度与多通道扫描实战

本文深入探讨了STM32G474系列单片机的ADC高级应用,包括硬件过采样技术实现16位精度和多通道扫描结合DMA的自动数据采集方案。通过详细的配置步骤和实战案例,帮助开发者突破传统电压测量局限,提升信号采集精度和系统效率,适用于工业监控、医疗设备等高精度应用场景。

weixin_42647395的博客 238

POJ 1404 I-Keyboard 二维dp

这是今天周赛的一道题目,比赛的时候没有做出来,后来听ZP说不是很难,就问了一下,然后写了写。。。期间芳姐给我指正了一些错误。。。 题目的意思是:给你一些按键使用的次数,然后让你,输出把这些字母怎么安排的给定的按键上可以使的所有字母需要按动的次数最小,(这里是以前的那种九宫格的按键安排)。 解体的思路:这是一道很经典的dp,在所给的条件中先预处理出来,第i个字母如果和第j个字母在一个按键上,这个

I am a slow walker, but I never walk backwards! 1085

管好 SAP Fiori Launchpad Content:技术目录、业务目录与 KPI 工具的完整治理思路

SAP Fiori Launchpad 作为企业级统一入口,需通过技术目录(源对象)和业务目录(引用编排)分层治理。技术目录由 Launchpad App Manager 维护,负责应用描述对象(Tile 和 Target Mapping)的创建与管理;业务目录由 Launchpad Content Manager 编排,通过引用技术目录对象实现灵活配置。分析型内容则通过 F2814 统一管理。这种分层设计支持应用复用,便于升级维护,是 SAP S/4HANA 项目中实现高效内容治理的关键。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 130

HFSS实战项目——高带外抑制特性SIW带通滤波器

本文对单级滤波器和双级滤波器的设计、工作原理及仿真结果进行了详细分析,并验证了双级SIW带通滤波器在性能方面的优越性,为微波通信系统中滤波器的设计和应用提供了重要参考。

2401_87464239的博客 1815

poj 1404 I-Keyboard(dp+输出最优解)

poj 1404 I-Keyboard(dp+输出最优解)

PKU_ZZY的博客 1084

AI Agent驱动的多模态情感分析方法:从BERT到Vision Transformer的探索

情感分析(Sentiment Analysis)是自然语言处理(NLP)与计算机视觉(CV)中一项重要任务。传统的情感分析主要依赖于文本数据,但在现实应用中,情感往往通过 语言、语音、表情、姿态 等多模态信号共同传达。因此,结合 多模态深度学习 的 AI Agent 在情感理解中具有广阔的前景。

一键难忘的博客 738

poj 1404 I-Keyboard dp输出方案

//poj 1404 //sep9 #include using namespace std; int k,l; int frequency[128]; int cost[128][128],price[128][128],idx[128][128]; char keys[128],letters[128]; void ini() { memset(price,0x40,sizeof(pric

sepNINE的专栏 788

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

POJ 1404 I-Keyboard (DP)

http://poj.org/problem?id=1404 题意 :手机上的要发短信的话,“我”字需要先按一下9键,再按3下6键,所以,现在想要重新布局每个键上的字母数,让最后的那个值最小,也就是说给你L个字母出现频率,让你将其分布在K个键上,字母顺序不可以变,每个字母出现的频率乘上他所在键的位置,再加总和最小即可。如果有多个解,尽量将字母往后边的键安排。 思路 :表示比赛的时候根本没看出这...

weixin_30664539的博客 81

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

POJ 1404 I-Keyboard G++ dp dfs 没掌握

手机输入

woniupengpeng的专栏 735

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

I-Keyboard - POJ 1404 dp

I-Keyboard Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 4269   Accepted: 2092 Description Most of you have probably tried to type an SMS message on the

提比的强行AC 695

I-Keyboard

问题描述 Sphere Online Judge (SPOJ) 网站的第14道题目是:“I-Keyboard”,如下所示: SPOJ Problem Set (classical) 14. I-Keyboard Problem code: IKEYB Most of you have probably tried to type an SMS message on the keypad ...

weixin_33775582的博客 281

Poj 1401 Factorial 题解

Poj 1401 Factorial 题目信息 Description The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the...

吃口雪花的博客 424

HDU 1124 - Factorial(简单数论)

Factorial Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5414 Accepted Submission(s): 3503 Problem Description The most important part of a...

在读NLP硕士 319

练习9(数论初步)

A - 整除的尾数 一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢? Input输入数据有若干组,每组数据包含二个整数a,b(0 Output对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。 Sample Input 200 40 1992 95 0

qq_26973089的博客 1398

实验课.简单数学(基本数学题)

很早就想整理一下,但一直苦苦哀叹,(其实就是我懒) 简单数学题暂时分为四个基本点: 1.求阶乘最右侧的数字: 当时这道题一直炸,其实思路很好懂,就是细节的处理。 初始思路:不断对十求余; 但是仔细思考一下,不断求余的话,量太大了,开ll也会炸掉; 以下为AC代码: (1): #include #include #include #include #include #include #includ...

weixin_44018261的博客 375

zstuACM 问题 J: 简单的算术1179

《简单的》算数 zstuOJ:http://47.96.116.66/problem.php?cid=3291&pid=9 POJ:http://poj.org/problem?id=1396 中文题目:(zstuOJ) 题目描述 新的WAP门户网站的一部分也是计算器,计算具有很长数字的表达式。为了使输出看起来更好,结果的格式与通常用于手动计算的方式相同。你的任务是编写这个计算器的核心部分。 给定两个数字和请求的操作,您将计算结果并以下面指定的格式输出它:加法和减法,一个数字写在另一个数字的下方。乘

追殇 | Blog 416

poj 1404 dp(手机按键编码最小)

题意:设计一种手机按键,使得频率打

dearmango 757
上一篇: Bookshelf题解动态规划DP
下一篇: POJ1463Strategic game题解动态规划DP
power721
博客等级 码龄18年 176粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值