日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Xtreme8.0 - Kabloom dp

發布時間:2023/12/13 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的Xtreme8.0 - Kabloom dp的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。