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.pswp.cn/news/254232.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/254232.shtml
英文地址,請注明出處:http://en.pswp.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…