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;
}
}
Xtreme8.0 - Kabloom dp的更多相关文章
- Xtreme8.0 - Kabloom 动态规划
Xtreme8.0 - Kabloom 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/kablo ...
- Xtreme8.0 - Play with GCD dp
Play with GCD 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/play-with-g ...
- Xtreme8.0 - Back to Square 1 数学
Back to Square 1 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/back-to- ...
- Xtreme8.0 - Magic Square 水题
Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/ ...
- Xtreme8.0 - Sum it up 水题
Sum it up 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/sum-it-up Descr ...
- 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 分类: dp 2015-05-21 10:50 14人阅读 评论(0) 收藏
Description 急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并 ...
- ZOJ 3822 Domination 概率dp 难度:0
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge Edward is the headm ...
- hdu3853 LOOPS(概率dp) 2016-05-26 17:37 89人阅读 评论(0) 收藏
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏
FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...
随机推荐
- bzoj千题计划205:bzoj1966: [Ahoi2005]VIRUS 病毒检测
http://www.lydsy.com/JudgeOnline/problem.php?id=1966 f[i][j] 表示s的前i个和t的前j个是否匹配 转移看代码 注意初始化: f[0][0]= ...
- BZOJ2301:莫比乌斯反演+二维容斥解决GCD范围计数
这个题是刚才刷的第一道反演题的拓展版,加上一个容斥就可以了 #include<cstdio> #include<algorithm> using std::min; ; int ...
- Matrix67|自由职业者,数学爱好者
Matrix67|自由职业者,数学爱好者 介绍一下你自己和所做的工作. 我叫顾森,网名 Matrix67,长住北京的重庆人,目前没有固定的职业.一会儿当当码农,一会儿做做编辑,一会儿教教数学,一会儿写 ...
- 【原创】backbone1.1.0源码解析之Model
趁热打铁,将Backbone.Model的源代码注释也发出来. Model是用来干嘛的?写过mvc的同学应该都知道,说白了就是model实例用来存储数据表中的一行数据(row) Backbone利用m ...
- [整理]定义但未初始化赋值的局部变量与OXCCCCCCCC
开发环境 : win7 32bit ,VS2010,先看一段C代码: #include <stdio.h> int main(){ int x; //-858993460 printf(& ...
- spring Mvc + Maven + 拷贝插件 (十一)
maven-antrun-plugin:可用于在项目编译打包时,把文件指定的文件拷贝到指定的位置,我们打包一般都是打包到 项目 的target 文件下; <groupId>org.apac ...
- ie8下jquery改变PNG的opacity出现黑边
复制网上的,没有他们那个类型的博客,所以就直接复制了 这些天在做一个效果,鼠标经过,PNG图片由透明变成不透明,jquery代 码:$(element).animate({"opacity& ...
- [机器学习&数据挖掘]SVM---核函数
1.核函数概述: 核函数通俗的来说是通过一个函数将向量的低维空间映射到一个高维空间,从而将低维空间的非线性问题转换为高维空间的线性问题来求解,从而再利用之前说的一系列线性支持向量机,常用的核函数如下: ...
- UVALive 6467 Strahler Order
> 题目链接 题意:给定一个有向图,顶点代表水池,入度为零的定点代表水源,等级是1,他们延河道(有向边)冲撞,对于普通的水池来说,题目给定判断它等级的两个准则,问出度为零的那个点的等级是多少. ...
- Android学习笔记——从源码看Handler的处理机制
可能是出于性能的考虑,Android的UI操作是非线程安全的. 也就是说,如果你在一个新开的线程中直接操作UI是会引发异常的. 但是,Android又规定,不要去阻塞UI线程!否则,轻者引起程序卡顿, ...