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;
}
}

Xtreme8.0 - Kabloom 动态规划的更多相关文章

  1. Xtreme8.0 - Kabloom dp

    Xtreme8.0 - Kabloom 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/kablo ...

  2. Xtreme8.0 - Magic Square 水题

    Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/ ...

  3. Xtreme8.0 - Sum it up 水题

    Sum it up 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/sum-it-up Descr ...

  4. Xtreme8.0 - Back to Square 1 数学

    Back to Square 1 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/back-to- ...

  5. Xtreme8.0 - Play with GCD dp

    Play with GCD 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/play-with-g ...

  6. leetcode算法笔记:二叉树,动态规划和回溯法

    在二叉树中增加一行 题目描述 给定一个二叉树,根节点为第1层,深度为 1.在其第 d 层追加一行值为 v 的节点. 添加规则:给定一个深度值 d (正整数),针对深度为 d-1 层的每一非空节点 N, ...

  7. 每日一题 LeetCode 486. 预测赢家 【递推】【前缀和】【动态规划】

    题目链接 https://leetcode-cn.com/problems/predict-the-winner/ 题目说明 题解 主要方法:递推:动态规划:前缀和 解释说明: 求前缀和 pre_nu ...

  8. 编辑距离——Edit Distance

    编辑距离 在计算机科学中,编辑距离是一种量化两个字符串差异程度的方法,也就是计算从一个字符串转换成另外一个字符串所需要的最少操作步骤.不同的编辑距离中定义了不同操作的集合.比较常用的莱温斯坦距离(Le ...

  9. LeetCode----Array

    Remove Duplicates from Sorted Array 思路:两个指针,头指针在0,尾指针从1开始寻找,找到第一个不等于头指针值的数,覆盖掉头指针后面那个数,然后尾指针往后移. pub ...

随机推荐

  1. POJ - 1753 Flip Game(状压枚举)

    https://vjudge.net/problem/POJ-1753 题意 4*4的棋盘,翻转其中的一个棋子,会带动邻接的棋子一起动.现要求把所有棋子都翻成同一种颜色,问最少需要几步. 分析 同一个 ...

  2. Java SSM框架之MyBatis3(一)MyBatis入门

    MyBatis3介绍 mybatis就是一个封装来jdbc的持久层框架,它和hibernate都属于ORM框架,但是具体的说,hibernate是一个完全的orm框架,而mybatis是一个不完全的o ...

  3. BAT及各大互联网公司2014前端笔试面试题--JavaScript篇(昨天某个群友表示写的简单了点,然后我无情的把他的抄了一遍)

    (某个群友)http://www.cnblogs.com/coco1s/ 很多面试题是我自己面试BAT亲身经历碰到的.整理分享出来希望更多的前端er共同进步吧,不仅适用于求职者,对于巩固复习js更是大 ...

  4. 20155206 2016-2017-2 《Java程序设计》第8周学习总结

    20155206 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 第十五章 通用API 15.1 日志 日志API简介 java.util.logging包提 ...

  5. HDU 4508 湫湫系列故事——减肥记I (完全背包)

    题意:有n种食物,每种食物可以给湫湫带来一个幸福感a,同时也会给她带来b的卡路里的摄入,然后规定她一天摄入的卡路里的量不能超过m,一共有n种食物,问可以得到的 最大的幸福感是多少? 解题报告:一开始以 ...

  6. ubuntu16.04系统搜狗输入法的安装

    参考博客:https://www.cnblogs.com/lrj567/p/6307329.html 本来不想写的,但是最近老是重装系统,每次百度特别浪费时间,特此记录一下 先去官网下载搜狗输入法li ...

  7. ZeroMQ安装说明

    ZeroMQ安装说明 1.   安装 1.1.Linux zmq安装 安装过程参考地址:http://zeromq.org/intro:get-the-software的说明 安装步骤如下(在安装时参 ...

  8. 转:vue2.0 keep-alive最佳实践

    转载至:https://segmentfault.com/a/1190000008123035 1.基本用法 vue2.0提供了一个keep-alive组件用来缓存组件,避免多次加载相应的组件,减少性 ...

  9. tortoise svn 忽略bin、obj等文件夹

    项目空白处右击 =>TortoiseSVN => Properties => New => Other => svn:global-ignores value => ...

  10. NOIp 2018 普及组

    T1标题统计 传送门 题目描述 凯凯刚写了一篇美妙的作文,请问这篇作文的标题中有多少个字符? 注意:标题中可能包含大.小写英文字母.数字字符.空格和换行符.统计标题字 符数时,空格和换行符不计算在内. ...