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. PHP中的面向对象 中的类(class)

    2.11 上午讲的是面向对象中的类(class),一个非常抽象的概念, 类里面成员的定义有 public$abc; private$abc(私有变量): protect $abc(受保护的变量): 下 ...

  2. 用EasyDarwin进行IPTV rtsp mpeg-ts smil流的转发和分发直播服务

    对RTSP/RTP的转发和分发一直都是EasyDarwin的基础功能,尤其是在安防行业中,EasyDarwin非常贴合安防监控的需求,但一直未尝试用EasyDarwin进行IPTV的RTSP流进行转发 ...

  3. Hibernater中的持久化对象以及状态转换

    一.持久化对象的要求 1.提供一个无参的构造器:使Hibernate可以使用Constructor.newInstance() 来实例化持久化类. 2.提供一个标识属性(identifier prop ...

  4. cocos2d-js实现 双击android后退按钮 即退出游戏

    之前测了一下android自带的后退按钮,用在cocos2d-js中是没有获取到的 (可能是cocos2d-js已经把android的后退事件截取了,所以原生java代码没有用), 没办法就只能用co ...

  5. [IR课程笔记]统计语言模型

    Basic idea 1.一个文档(document)只有一个主题(topic) 2.主题指的是这个主题下文档中词语是如何出现的 3.在某一主题下文档中经常出现的词语,这个词语在这个主题中也是经常出现 ...

  6. Lua学习笔记(1) ——语法

    1.  Lua -i main.lua -i 进入交互模式 -l 加载一个库 -e  “lua code” 直接在命令行执行lua code 2. 注释 -- This is a line comme ...

  7. 使用adb命令查看android中的数据库

    在采用数据库操作时,经常会出现查询或删除等操作语句执行失败,但是有找不到具体原因.下面将介绍一种命令行方式进行数据库操作,来验证android中的数据库操作语句是否正确等. 具体操作步骤如下: (1) ...

  8. WSDL文档深入分析

    借助jdk的wsimort.exe工具生成客户端代码 格式:wsimport -keep url   //url为wsdl文件的路径 直接生成客户端代码会抛异常, 无法生成客户端代码, 解决办法: 将 ...

  9. HDU5877 Weak Pair dfs + 线段树/树状数组 + 离散化

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5877 题意: weak pair的要求: 1.u是v的祖先(注意不一定是父亲) 2.val[u]*va ...

  10. html5--5-6 绘制圆/弧

    html5--5-6 绘制圆/弧 学习要点 掌握arc() 方法创建圆弧/曲线(用于创建圆或部分圆) 矩形的绘制方法 rect(x,y,w,h)创建一个矩形 strokeRect(x,y,w,hx,y ...