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. Bzoj2780: [Spoj]8093 Sevenk Love Oimaster

    题目 传送门 Sol 就是广义\(sam\) 然后记录下每个状态属于哪些串,开\(set\)维护 \(parent\)树上启发式合并一下就好了 # include <bits/stdc++.h& ...

  2. 经典的 div + css 鼠标 hover 下拉菜单

    经典的 div + css 鼠标 hover 下拉菜单 效果图: 源码: <html> <head> <meta charset="utf-8"> ...

  3. unity对象物体闪烁

    Material mat; // float a=0; //控制闪烁速度 float speed=0.6f; float b=1; Update(){ if(a>0.3f){ b=1; } if ...

  4. Docker bridge探索

    作者:ellen.sun链接:http://blog.daocloud.io/docker-bridge/著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 早期的二层网络中,bri ...

  5. spring boot(2)-@SpringBootApplication详解

    pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  6. vuejs plus d3

    vuejs 是一个数据驱动视图的前端框架,一切皆可以作为可重用的组件加以使用. d3则是数据可视化javascript库,如何将二者的长处相结合是一个挑战. https://tyronetudehop ...

  7. ASP.NET错误处理的方式(一)

    对Web应用程序来说,发生不可预知的错误和异常在所难免,我们必须为Web程序提供错误处理机制.当错误发生时,我们必须做好两件事情:一是将错误信息记录日志,发邮件通知网站维护人员,方便技术人员对错误进行 ...

  8. 二、WPF datagrid 行变色

    public void Color(){ DataGridRow row1 = (DataGridRow)this.dgSource.ItemContainerGenerator.ContainerF ...

  9. listview的pushBackDefaultItem中的item属性被修改问题

    time:2015/05/04 1. 描述 在cocostudio中有两个控件,一个listview,另外一个是隐藏的imageview,其中后者作为listview的元素.每次使用的时候把Image ...

  10. Linux 硬件RAID详解系统功能图

    RAID-0(条带模式) 特点: 在读写的时候可以实现并发,所以相对其读写性能最好,每个磁盘都保存了完整数据的一部分,读取也采用并行方式,磁盘数量越多,读取和写入速度越快. 因为没有冗余,一个硬盘坏掉 ...