博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【二进制枚举+LCS】Card Hand Sorting
阅读量:5140 次
发布时间:2019-06-13

本文共 2344 字,大约阅读时间需要 7 分钟。

【二进制枚举+LCS】Card Hand Sorting

题目描述

When dealt cards in the card game Plump it is a good idea to start by sorting the cards in hand by suit and rank. The different suits should be grouped and the ranks should be sorted within each suit. But the order of the suits does not matter and within each suit, the cards may be sorted in either ascending or descending order on rank. It is allowed for some suits to be sorted in ascending order and others in descending order.

Sorting is done by moving one card at a time from its current position to a new position in the hand, at the start, end, or in between two adjacent cards. What is the smallest number of moves required to sort a given hand of cards?

输入

The first line of input contains an integer n (1 ≤ n ≤ 52), the number of cards in the hand. The second line contains n pairwise distinct space-separated cards, each represented by two characters. The first character of a card represents the rank and is either a digit from 2 to 9 or

one of the letters T , J , Q , K , and A representing Ten, Jack, Queen, King and Ace, respectively, given here in increasing order. The second character of a card is from the set { s , h , d , c } representing the suits spades ♠, hearts ♥, diamonds ♦, and clubs ♣.

输出

Output the minimum number of card moves required to sort the hand as described above.

样例输入

7

9d As 2s Qd 2c Jd 8h

样例输出

2

看一眼,52,嗯 状态压缩 暴力 二进制枚举?然后,怎么换啊,不会。好难。。。

比赛结束,LCS,嗯,会了
LCS差点不会写...尴尬
通过移位符判断位置。

#include
using namespace std;#define ll long longmap
mp;inline void init(){ for(int i=2;i<=9;++i){ mp[i+'0']=i; } mp['T']=10; mp['J']=11; mp['Q']=12; mp['K']=13; mp['A']=14; mp['s']=0; mp['h']=1; mp['d']=2; mp['c']=3;}struct node{ int id; int val; int block; int k;}s[55];int dp[55],n;inline bool cmp(node x,node y){ if(x.k==y.k){ return x.val
s[j].id){ dp[i]=max(dp[j]+1,dp[i]); } } ans=max(dp[i],ans); } return ans;}int main(){ init(); scanf("%d",&n); char str[3]; for(int i=0;i
>s[j].k)&1)!=1?-1:1); } sort(s,s+n,cmp); ans=min(ans,n-lcs()); } }while(next_permutation(arr,arr+4));//全排列 printf("%d\n",ans); return 0;}

转载于:https://www.cnblogs.com/smallocean/p/9749053.html

你可能感兴趣的文章
CSS属性值currentColor
查看>>
《DSP using MATLAB》Problem 7.37
查看>>
python基础学习第二天
查看>>
java可重入锁reentrantlock
查看>>
浅谈卷积神经网络及matlab实现
查看>>
解决ajax请求cors跨域问题
查看>>
《收获,不止Oracle》pdf
查看>>
LinkedList<E>源码分析
查看>>
Real-Time Rendering 笔记
查看>>
如何理解HTML结构的语义化
查看>>
Activity之间的跳转:
查看>>
实验四2
查看>>
Android现学现用第十一天
查看>>
多路复用
查看>>
Python数据可视化之Pygal(雷达图)
查看>>
Java学习笔记--字符串和文件IO
查看>>
转 Silverlight开发历程—(画刷与着色之线性渐变画刷)
查看>>
SQL语法(3)
查看>>
在js在添版本号
查看>>
sublime3
查看>>