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;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
详细介绍:    手机数据恢复一直以来都是一个较为难处理的问题,因为手机数据的易覆盖性,也导致了手机数据恢复的成功率低,并且手机类数据大多涉及到个人隐私,很多人也不愿意轻易交给工程师进行操作,担心数据会被泄露,现在有了赤兔Android 8000,再也不用担心这个问题,3步轻松恢复丢失各种手机数据!    赤兔Android 8000是一款专门应用于Android手机的数据恢复软件,能够轻松地恢复Android手机因中病毒、误删除、误格式化、恢复出厂、刷机等原因丢失短信以及联系人、微信QQ聊天记录、手机照片、手机视频、通话记录、手机录音等数据的恢复。操作方法极其简单,让您在短短的几分钟内就能够轻松恢复手机丢失数据,从此不再为Android手机数据丢失而烦恼! 一、产品特色介绍: 1. 通杀所有android版本,从2.x一直支持到4.x 2、能够恢复安卓手机中误操作丢失的短信内容    3、能够恢复删除丢失的联系人、通话记录    4、能够恢复删除微信、QQ聊天记录    5、支持恢复手机视频、手机照片、手机录音等数据    6、试用版软件支持预览丢失数据    7、能够搜索指定联系人或者电话号所有短信、通讯录等 8、设备均需root之后才可以扫描,支持扫描镜像文件 9、 支持通讯录,通话记录,短信,视频,照片等文件的碎片级恢复 10、试用版软件支持预览丢失数据 软件下载地址:http://pan.baidu.com/s/1eQpDYUm 作者网站:http://www.sysfix.cn 联 系 人:QQ:1253140355 邮箱:support@sysfix.cn 电话:400-077-4377

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值