Xtreme8.0 - Kabloom dp

Xtreme8.0 - Kabloom

题目连接:

https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/kabloom

Description

The card game Kabloom is played with multiple decks of playing cards. Players are dealt 2 n cards, face up and arranged in two rows of n cards. The players must discard some of the cards, so that the cards that remain in the first row match the rank of the cards that remain in the second row. The cards match only in rank (e.g. an Ace of Hearts matches any other Ace regardless of suit), but they must appear in the same order in each row. The players are not able to rearrange the order in which the cards appear. Note also that a Joker can match any card including another Joker .
The goal is to maximize the sum of the point value of the cards that remain. Aces are worth 20 points, face cards are worth 15 points, and the numbered cards are worth the number on the card (e.g. the Seven of Clubs is worth 7 points).The value of a Joker is equal to the card with which it is matched, e.g. a Joker matched with an Ace is worth 20 points, a Joker matched with a face card is worth 15 points, etc. If two Jokers are matched with each other, they are worth 50 points each.

Input

The input is made up of multiple test cases (#test cases<=30, if 1<=n<=10 or #test cases<=10 if 10<=n<=1000). Each test case contains three lines of input.
The first line in each test case is an integer n , 1 <= n <= 1,000, indicating how many cards are in each row.
The second line of the test case will contain n symbols representing the ranks of the cards in the first row. Each symbol will be chosen from the list {A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, R}. The symbols in the list represent the following ranks, respectively, {Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Joker}. Similarly, the third line of the test case will contain the n symbols of the cards in the second row.
The input will end with a 0 on a line by itself.

Output

For each test case, output the value of the best Kabloom hand on a line by itself. Note that the cards that comprise the best Kabloom hand may not be unique for a test case.
Note: Every line of output should end in a newline character .

Sample Input

9
6 3 7 4 2 A K R T
3 5 4 7 R A Q K T
0

Sample Output

140

Hint

题意

给你2n个扑克牌,每行n张牌

你需要扔掉一些牌,使得上下两层牌一一对应。

如果两个A对应,那么可以得20分,如果是脸牌的话,那么就可以得15分,其他就是牌的分值。

王可以替代任意牌,如果是两张王牌对应的话,那么可以得50分。

问你最多可以得多少分,答案需要乘以2

题解

比较裸的dp,带权的最长公共子序列

代码

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+6;int add(char a,char b){if(a=='R'&&b=='R')return 50;if(a=='R'){if(b=='A')return 20;if(b=='Q')return 15;if(b=='K')return 15;if(b=='J')return 15;if(b=='T')return 10;return b-'0';}if(b=='R'){if(a=='A')return 20;if(a=='Q')return 15;if(a=='K')return 15;if(a=='J')return 15;if(a=='T')return 10;return a-'0';}if(a=='A')return 20;if(a=='Q')return 15;if(a=='K')return 15;if(a=='J')return 15;if(a=='T')return 10;return a-'0';
}
char a[maxn][5],b[maxn][5];
int n,dp[maxn][maxn];
int main()
{while(scanf("%d",&n)!=EOF){if(n==0)break;memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++)scanf("%s",a[i]);for(int i=1;i<=n;i++)scanf("%s",b[i]);for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){dp[i][j]=max(dp[i-1][j],dp[i][j-1]);if(a[i][0]==b[j][0]||a[i][0]=='R'||b[j][0]=='R'){dp[i][j]=max(dp[i][j],dp[i-1][j-1]+add(a[i][0],b[j][0]));}}}cout<<dp[n][n]*2<<endl;}
}

转载于:https://www.cnblogs.com/qscqesze/p/5958735.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/254232.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

视频编码中封装格式RMVB,AVI,264

常规理解 封装格式&#xff08;也叫容器&#xff09;&#xff0c;就是将已经编码压缩好的视频轨和音频轨按照一定的格式放到一个文件中&#xff0c;也就是说仅仅是一个外壳&#xff0c;或者大家把它当成一个放视频轨和音频轨的文件夹也可以。说得通俗点&#xff0c;视频轨相当…

halcon圆环完整度检测

文章目录处理要求程序源码处理结果博主写作不容易&#xff0c;孩子需要您鼓励 万水千山总是情 , 先点个赞行不行 处理要求 查找好的圆环&#xff0c;检测圆环不良 程序源码 read_image (Image, F:/HALCON/圆环完整性检测/6.bmp) rgb1_to_gray (Image, GrayImage) v…

《SAS编程与数据挖掘商业案例》学习笔记之十五

继续《SAS编程与数据挖掘商业案例》读书笔记&#xff0c;本次重点&#xff1a;输出控制 主要内容包含&#xff1a;log窗体输出控制、output窗体输出控制、ods输出控制 1.log窗体输出控制 将日志输出到外部文件 proc printto log "f:\data_model\book_data\chapt9\newlog.t…

[转载]MATLAB movie 函数动态绘图

原文地址&#xff1a;MATLAB movie 函数动态绘图作者&#xff1a;小霖cheeronMATLAB movie 函数动态绘图 电影动画的好处就是&#xff0c;运行一次可以多次播放&#xff0c;甚至可以直接生成avi文件&#xff0c;直接独立与Matlab环境播放。这是其它三种动画制作方法所不具备的。…

圆环划痕检测halcon

文章目录处理要求处理源码处理效果博主写作不容易&#xff0c;孩子需要您鼓励 万水千山总是情 , 先点个赞行不行 处理要求 查找圆环缺陷 处理源码 read_image (Image, F:/HALCON/圆环划痕处理/10_33221_ba4582f0e88ec79.bmp) rgb3_to_gray (Image, Image, Image, Image…

多播(组播)原理分析

为什么要使用多播:网 卡从网络上接收到目标物理地址对应的所有bit位都为1的数据报时&#xff0c;会收到这条消息并将其上传给驱动程序&#xff0c;网卡的这种工作模式称为广播模式&#xff0c;网卡的缺省工作模式包含直接模式和广播模式。利用这一特性&#xff0c;UDP&#xff…

iftop

在类Unix系统中可以使用top查看系统资源、进程、内存占用等信息。查看网络状态可以使用netstat、nmap等工具。若要查看实时的网络流量&#xff0c;监控TCP/IP连接等&#xff0c;则可以使用iftop。一、iftop是什么&#xff1f;iftop是类似于top的实时流量监控工具。官方网站&…

sql 日记

--4.选择雇用时间在1998-02-01到1998-05-01之间的员工姓名&#xff0c;job_id和雇用时间select last_name,job_id,hire_datefrom employeeswhere to_char(hire_date,yyyy-mm-dd) between 1998-02-01 and 1998-05-01 --5.选择在20或50号部门工作的员工姓名和部门号select last_n…

CSS3中的变形处理

变形分类 缩放 使用scale方法来实现文字或图像的缩放&#xff0c;在参数中指定缩放倍率。例如“scale&#xff08;0.5&#xff09;”&#xff0c;表示缩小50 倾斜 使用skew方法来实现文字或图像的缩放&#xff0c;在参数中指定水平方向的倾斜角度与垂直方向的倾斜角度&#xf…

linux基本知识学习

LINUX黑洞 /dev/null 这是一个虚设的设备&#xff0c;俗称“LINUX 黑洞”&#xff0c;任何对/dev/null的写入都会成功&#xff0c; 但是数据会消失得无影无踪&#xff0c;没有任何反馈。所以经常把不想在屏幕 显示的信息全部送到/dev/null&#xff0c;在shell脚本中用得较多。 …

日志OLAP:在SQL中使用UDF, lambda函数使用案例

场景 日志服务内置了20类SQL函数。面对用户复杂的业务场景&#xff0c;例如使用json来沉淀业务数据&#xff0c;普通的SQL函数可能就无法满足需求&#xff0c;需要一些用户自定义处理逻辑。为了处理json类的业务数据&#xff0c;我们可以采用把json展开成多行的形式进行统计分析…

瓶子个数计数halcon

文章目录处理要求处理方法一源码效果方法二源码效果博主写作不容易&#xff0c;孩子需要您鼓励 万水千山总是情 , 先点个赞行不行 处理要求 查找纸箱内瓶子个数 处理方法一 源码 dev_clear_window () dev_open_window (0, 0, 640*1.5, 512*1.5, black, WindowHandle…

lightoj1060_组合数学

http://lightoj.com/volume_showproblem.php?problem1060 有一些用尼康托展开http://blog.csdn.net/niushuai666/article/details/6611131&#xff0c;简单的尼康托&#xff0c;每个字母多个数的还不会 组合数学解看起来比较简单 给定一个字符串和k&#xff0c;求字符串第k大字…

几个so经常使用Function

SD_WF_ORDER_REJECT SO拒绝 RV_ORDER_FLOW_INFORMATION 获得凭证流&#xff0c;支持OBD&#xff0c;SO等 call function RV_ORDER_FLOW_INFORMATION exporting aufbereitung 2 belegtyp C comwa l_comwa…

LIVE555建立RTSP服务记录

在官网上面 http://www.live555.com/liveMedia/#config-unix下载最新源码&#xff0c;并进行编译&#xff0c;同时官网上面告诉了你怎么样编译已经不同平台对应需要修改的内容 一、arm_linux_g下面编译视频文件LIVE555 【config.armlinux】 CROSS_COMPILE arm-none…

halcon自动对焦算法

1、介绍 图像清晰度是衡量图像质量的一个重要指标&#xff0c;对于相机来说&#xff0c;其一般工作在无参考图像的模式下&#xff0c;所以在拍照时需要进行对焦的控制。对焦不准确&#xff0c;图像就会变得比较模糊不清晰。相机对焦时通过一些清晰度评判指标&#xff0c;控制镜…

HTML学习笔记06-连接

HTML超链接 HTML使用标签<a>来设置文本超链接。 超链接可以是文字&#xff0c;也可以是图片&#xff0c;点击这些内容跳转到新的文档或当前文档的某个部分 代码类似这样&#xff1a; <a href"url">连接文本</a> 实例&#xff1a; <!DOCTYPE HTM…

在Xcode中使用Git进行源码版本控制

在Xcode中使用Git进行源码版本控制 在应用程序开发过程中&#xff0c;很重要的一部分工作就是如何进行源码的版本控制。当代码出现问题时&#xff0c;我们就需要将代码恢复到原先正常的版本。如果是多个人共同开发一个项目&#xff0c;那么代码的控制就会非常复杂。幸运的是&am…

Linux环境变量的设置和查看方法

1. 显示环境变量HOME $ echo $HOME /home/redbooks 2. 设置一个新的环境变量hello $ export HELLO"Hello!" $ echo $HELLO Hello! 3. 使用env命令显示所有的环境变量 $ env HOSTNAMEredbooks.safe.org PVM_RSH/usr/bin/rsh Shell/bin/bash TERMxterm HISTSIZE1000 ..…

CefSharp试用

Github地址&#xff1a; https://github.com/cefsharp/CefSharp 首先下载所有源代码下来 然后直接打开Sln 然后就可以直接调试WinForm、Wpf的Example了 注意地方&#xff1a; CefSharp.Core、CefSharp.BrowserSubprocess.Core 这两个类库是用C写的&#xff0c;所以VisualStudio…