local function getmjvalnew(key)
local keynew = {}
local sumnval = 0
for _, v in ipairs(key) do
if v<=0 and next(keynew) then
sumnval = sumnval + getmjvalnew(keynew)
keynew = {}
elseif v>0 then
table.insert(keynew, v)
end
end
key = keynew
if not next(key) then return sumnval end
local fval = 0
if key[1] > 2 then
local newarr2 = clone(key)
newarr2[1] = newarr2[1] - 3
local nval = getmjvalnew(newarr2) + 1
if nval > fval then
fval = nval
end
end

if key[2] and key[3] and key[2]>0 and key[3]>0 then
local newarr2 = clone(key)
newarr2[1] = newarr2[1] - 1
newarr2[2] = newarr2[2] - 1
newarr2[3] = newarr2[3] - 1
local nval = getmjvalnew(newarr2) + 1
if nval > fval then
fval = nval
end
end

if #key > 1 then
local newarr2 = clone(key)
table.remove(newarr2, 1)
local nval = getmjvalnew(newarr2)
if nval > fval then
fval = nval
end
end
return sumnval + fval
end

local all = {}
function calcdx(al, n)
if all[n] then return all[n] end
all[n] = getmjvalnew(al)
end

local function calsum(n)
local ret = 0
local al = {}
while(n>0)do
table.insert(al, 1, n%10)
ret = ret + n%10
n = math.floor(n/10)
end
return ret, al
end

function spawnmj(n)
local sum, al = calsum(n)
if sum > 14 or #al > 9 then
return
end

if n > 0 then
calcdx(al, n)
print(n, all[n])
end

if #al == 9 then return end

for _,k in ipairs({1,2,3,4}) do
if sum + k<= 14 then
spawnmj(n*10+k)
end
end
end

spawnmj(0)
dump_t2f(all, "mjdx.lua")

spown mj的更多相关文章

  1. sicily 1027 MJ, Nowhere to Hide 字符串匹配与排序

    1027. MJ, Nowhere to Hide Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description On BBS, th ...

  2. 【代码笔记】iOS-MBProgressHUD+MJ

    一,效果图. 二,工程图. 三,代码. ViewController.m #import "ViewController.h" #import "MBProgressHU ...

  3. MJ瀑布流学习笔记

    1. 如果系统自带的布局的话,是这样: //系统自带的UICollectionViewFlowLayout 而不是UICollectionViewLayout UICollectionViewFlow ...

  4. MJ刷新控件MJRefreshFooterView上拉之后收不回来的解决办法

    修改MJRefreshFooterView.m文件中的这个方法 #pragma mark - 状态相关 #pragma mark 设置状态 - (void)setState:(MJRefreshSta ...

  5. 使用 MJ 自定义下拉刷新

    // // ViewController.m // Refresh // // Created by Apple on 16/7/19. // Copyright © 2016年 mac. All r ...

  6. 旧Mj下拉刷新 An instance 0xca90200 of class UITableView was deallocated while key value observers were s

    An instance 0xca90200 of class UITableView was deallocated while key value observers were still regi ...

  7. python 3.6 MJ小工具

    2017.07.14 update 做了个界面,不需要使用cmd命令行+文件路径的方式来使用了: 链接如下: http://www.cnblogs.com/chenyuebai/p/7150382.h ...

  8. 看完MJ讲解的单例后的个人总结

    1.单例的介绍 单例是iOS常用的开发模式的一种. 2.什么是单例 单例就是一个类只创建一个对象,只分配一次内存空间. 3.单例的应用场景 1)系统的单例:  [UIApplication share ...

  9. Sicily 1027. MJ, Nowhere to Hide

    //就是一个简单的字符串配对~~用map来解决很easy #include <iostream> #include <map> #include <string> ...

随机推荐

  1. wlpt的提现功能

    1.<transaction id="WithdrawPre" template="pageLoaderTemplate"> <actions ...

  2. bzoj1458 士兵占据

    1458: 士兵占据 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 685  Solved: 398 [Submit][Status][id=1458 ...

  3. asp识别手机端

    <script type="text/javascript"> var mobileAgent = new Array("iphone", &quo ...

  4. mysql_num_rows

    mysql记录总条数 $sql3 = "select * from inviter where tuijianren = '$session' "; $res3 = mysql_q ...

  5. PHP获取IP

    <?php $iipp = $_SERVER["REMOTE_ADDR"]; echo $iipp ; ?>

  6. js 怎么传递参数

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  7. 图片转base64存储

    图片转base64存储 base64.b64encode(r.content) url='http://www.heze.cn/info/themes/heze/Public/tel/?tel=MDU ...

  8. TControl,TWinControl和TGraphicControl的显示函数

    -------------------------- 显示隐藏刷新 -------------------------- TControl = class(TComponent)procedure S ...

  9. BZOJ3231: [Sdoi2008]递归数列

    BZOJ3231: [Sdoi2008]递归数列 Description 一个由自然数组成的数列按下式定义: 对于i <= k:ai = bi 对于i > k: ai = c1ai-1 + ...

  10. git (转载)

    文章转载 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的 ...