Card Hand Sorting ,排列,状态压缩
来源:互联网 发布:淘宝虚拟充值 编辑:程序博客网 时间:2024/06/15 06:57
Card Hand Sorting Kattis - cardhand
题意
将n张扑克牌排序,排序规则,不同花色之间的顺序没有要求,同意花色之间必须升序或者降序,问使得整个扑克牌排好序最少需要移动多少次
分析
知识点
组合数学,状态压缩,最长上升子序列
花色之间的排序
升序或者降序
共有
参考代码
#include <iostream>#include <vector>#include <map>#include <algorithm>using namespace std;template <class It>int LCS(It begin,It end)//求最长上升子序列的长度{ typedef typename iterator_traits <It>::value_type T; T inf = 1<<30; vector<T> Best(end-begin,inf); for(It i = begin ; i != end; ++i) *lower_bound(Best.begin(),Best.end(),*i) = *i; return lower_bound(Best.begin(),Best.end(),inf) - Best.begin();}int main(void){ std::ios::sync_with_stdio(false); map<char,int> ma; ma['T'] = 10; ma['J'] = 11; ma['Q'] = 12; ma['K'] = 13; ma['A'] = 14; map<char,int> color; color['s'] = 0; color['h'] = 1; color['d'] = 2; color['c'] = 3; int n; char s[3]; int num[100]; int col[100]; int value[100]; while(cin>>n) { for(int i = 0; i < n; ++i) { cin>>s; if(ma.count(s[0])) num[i] = ma[s[0]]; else num[i] = s[0] - '0'; col[i] = color[s[1]]; } int ans = 0; int q[] = {0,1,2,3}; do { for(int dir = 0; dir < 16; ++dir)//2^4中升序降序的排列 { for(int i = 0; i < n; ++i) value[i] = q[col[i]] * 100 + num[i] * (1- 2*!!(dir&(1<<col[i])));//乘以二出现正负用来表示升序或者降序 ans = max(ans,LCS(value,value+n)); } } while(next_permutation(q,q+4));//4!种花色的排列 cout<<n-ans<<endl; } return 0;}
阅读全文
0 0
- Card Hand Sorting ,排列,状态压缩
- Card Hand Sorting 枚举+LCS
- card sorting
- hdu4336 Card Collector 状态压缩dp
- HDOJ 4336 Card Collector (状态压缩DP)
- HDU 4336 Card Collector 状态压缩+概率DP
- hdu 4336 Card Collector 概率DP 状态压缩DP
- hdu 4336 Card Collector 概率dp+状态压缩
- HDU 4336 Card Collector 状态压缩 概率DP
- hdu 4336 Card Collector(状态压缩概率dp)
- HDU 4336Card Collector 概率dp 状态压缩
- hdu-4336 Card Collector状态压缩|期望dp】
- HDU 4336 Card Collector(状态压缩+概率DP)
- 【HDU4336】Card Collector-状态压缩DP+期望DP
- HDU 4336 Card Collector(状态压缩dp+概率dp)
- Hdu 4336 Card Collector 概率DP+状态压缩
- WCST - Wisconsin Card Sorting Test
- Best Sequence(匹配+全排列(KMP+状态压缩))
- 优先队列
- python 爬虫爬取百度图片
- 【笔记】5、初学python3网络爬虫——正则表达式的基本使用
- office 在线浏览和编辑 部署 Office Web Apps Server
- p2p理财中坏习惯会让你入不敷出,要赶紧改掉
- Card Hand Sorting ,排列,状态压缩
- pom文件中报错:系统找不到指定的路 径。
- Win7 64位下载Apache服务器安装包及"缺少vcruntime140.dll"问题
- HTML 调整图像的大小,以及位置
- 舵机控制原理
- leetcode 258. Add Digits /371. Sum of Two Integers
- 如何引用Icommand并实现接口
- Json数据解析--JsonDemo
- 一张图解释典型编译程序结构框图