c++ 版连接 https://blog.csdn.net/canguanxihu/article/details/46363375

因为项目用的是lua脚本,看了C++版后自己写了一个lua版本的,原理在c++连接里面博主已经介绍了,我也不重复描述了,直接把代码贴出来

 local NewLogic = class("NewLogic")

 local handCardCount = 

 --随机生成扑克用于测试
function NewLogic:randomMakeCards() math.randomseed(os.time()) local cards = {} repeat
local card = math.random()
if not table.indexof(cards,card) then
table.insert(cards,card)
end
until(#cards == handCardCount) return cards
end -- o 1 转换排列组合法
function NewLogic:combination(cards,cbntNumber)
if cbntNumber > #cards then
return nil
end local assistArray = {}
for i = ,#cards do
if i <= cbntNumber then
assistArray[i] =
else
assistArray[i] =
end
end local cbntResult = {} local function getResult(astArray,srcArray,cbntResult)
local oneOfCombination = {}
for k,v in ipairs(astArray) do
if v == then
table.insert(oneOfCombination,srcArray[k])
end
end table.insert(cbntResult,oneOfCombination)
end getResult(assistArray,cards,cbntResult) local idx =
while true do
if assistArray[idx + ] == nil then
break
end if assistArray[idx] == and assistArray[idx + ] == then
assistArray[idx] =
assistArray[idx + ] = 1
for i = , idx - do
for j = i + , idx do
if assistArray[i] < assistArray[j] then
local mid = assistArray[i]
assistArray[i] = assistArray[j]
assistArray[j] = mid
end
end
end
         getResult(assistArray,cards,cbntResult)
idx =
else
idx = idx +
end
end return cbntResult
end return NewLogic

排列组合:01转换法之lua实现的更多相关文章

  1. UVa Problem 10132 File Fragmentation (文件还原) 排列组合+暴力

    题目说每个相同文件(01串)都被撕裂成两部分,要求拼凑成原来的样子,如果有多种可能输出一种. 我标题写着排列组合,其实不是什么高深的数学题,只要把最长的那几个和最短的那几个凑一起,然后去用其他几个验证 ...

  2. 蓝桥杯 问题 1110: 2^k进制数 (排列组合+高精度巧妙处理)

    题目链接 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2 ...

  3. 学习sql中的排列组合,在园子里搜着看于是。。。

    学习sql中的排列组合,在园子里搜着看,看到篇文章,于是自己(新手)用了最最原始的sql去写出来: --需求----B, C, F, M and S住在一座房子的不同楼层.--B 不住顶层.C 不住底 ...

  4. .NET平台开源项目速览(11)KwCombinatorics排列组合使用案例(1)

    今年上半年,我在KwCombinatorics系列文章中,重点介绍了KwCombinatorics组件的使用情况,其实这个组件我5年前就开始用了,非常方便,麻雀虽小五脏俱全.所以一直非常喜欢,才写了几 ...

  5. 【原创】开源.NET排列组合组件KwCombinatorics使用(三)——笛卡尔积组合

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  6. 【原创】开源.NET排列组合组件KwCombinatorics使用(二)——排列生成

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  7. 【原创】开源.NET排列组合组件KwCombinatorics使用(一)—组合生成

           本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...

  8. hdu1521 排列组合(指数型母函数)

    题意: 有n种物品,并且知道每种物品的数量ki.要求从中选出m件物品的排数.         (全题文末) 知识点: 普通母函数 指数型母函数:(用来求解多重集的排列问题) n个元素,其中a1,a2, ...

  9. [leetcode] 题型整理之排列组合

    一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...

随机推荐

  1. apm飞控飞行模式详解

    1.稳定模式Stabilize稳定模式是使用得最多的飞行模式,也是最基本的飞行模式,起飞和降落都应该使用此模式.此模式下,飞控会让飞行器保持稳定,是初学者进行一般飞行的首选,也是FPV第一视角飞行的最 ...

  2. spring boot(6)-JdbcTemplate访问数据库

     pom.xml 添加jdbc模块和mysql依赖 <dependency> <groupId>org.springframework.boot</groupId&g ...

  3. Linux虚拟机将ip改为自定义模式网络

    查看当前ip:ifconfig 配置linux的ip地址:vi /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO="dhcp" ...

  4. Frequently Used Algo

    1. 链表 链表逆转 class Solution { public: ListNode* reverseList(ListNode* head) { ListNode* prev = NULL; w ...

  5. [翻译] FLAnimatedImage

    FLAnimatedImage FLAnimatedImage is a performant animated GIF engine for iOS: FLAnimatedImage是一个播放gif ...

  6. [翻译] FSLineChart

    FSLineChart A line chart library for iOS. 一个iOS的线状图控件. Installing FSLineChart - 安装 Add the contents ...

  7. Linux 下Discuz论坛的搭建

    Discuz论坛的搭建[基于LNMP环境搭建成功后] ##创建BBS数据库在本地/远程服务器 mysql -uroot -proot create database bbs; show databas ...

  8. VS无法加载Web项目

    在VS中修改Web项目的服务器设置时无法加载改Web项目,提示如下图 原因:因为项目中的EbcBuy.Bll.Users.WebApi.csproj.user文件并没有加入到版本控制文件,所以讲项目还 ...

  9. windows系统镜像 微软官方资源便捷下载教程

    今天跟小师弟学到了一个下载软件的好办法,省得到各种网站下载带有病毒,插件的资源. 这个神奇的网站叫做   MSDN, 我告诉你,这是一个私人维护的网站,里面有各种官方软件的下载地址.可以直接用下载工具 ...

  10. 深入浅出SharePoint2012——安装Report Service

    安装顺序 Microsoft .NET Framework 3.5 SP1 report service installation,pls SQLServer2008R2SP1-KB2528583-x ...