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. jquery 通过ajax 提交表单

    1.需要引入以下两个js文件 <script src="Easyui/jquery-1.7.2.min.js"></script>    <scrip ...

  2. The basic principle of test case 修改引擎

    The basic principle of test case evaluation is that output resulting from running a test case is com ...

  3. macos下查看用户组,以及修改文件权限

    查看当前用户所属组 groups 查看指定用户所属组 groups username 更改权限 将单个文件更改为777权限 chmod 777 aaa.txt 更改文件夹所属组 sudo chown ...

  4. ETF到底是什么?

    ETF(交易所交易基金)是一种证券产品,它可以跟踪一些相关的资产,不论是股票.债券.商品,还是数字货币. ETF基金会负责跟踪指定的资产.然后放出部分股份,这些股份代表着对资产的拥有权. 交易ETF股 ...

  5. linux下环境搭建

    1.jdk https://ivan-site.com/2012/05/download-oracle-java-jre-jdk-using-a-script/ 在linux用wget直接下载JDK ...

  6. Android JNI技术介绍【转】

    本文转载自:http://blog.csdn.net/yangwen123/article/details/8085833 JNI是JavaNative Interface 的缩写,通过JNI,Jav ...

  7. css position弹性盒子测试

    总结: 1.利用样式height:100%设置div高度为全屏时候必须设置所有的父元素,但是父元素那么多,不可控,所以此法不可行: 2.设置父框架的padding为100px,div进行float,p ...

  8. 卡特兰数 HDU2067 & HDU4165 & HDU1134

    题目链接:https://vjudge.net/problem/HDU-2067 小兔的棋盘 Time Limit: 1000/1000 MS (Java/Others)    Memory Limi ...

  9. Zookeeper实现负载均衡原理

    先玩个正常的,好玩的socket编程: 服务端: 首先公共的这个Handler: package com.toov5.zkDubbo; import java.io.BufferedReader; i ...

  10. PYTHON 爬虫笔记三:Requests库的基本使用

    知识点一:Requests的详解及其基本使用方法 什么是requests库 Requests库是用Python编写的,基于urllib,采用Apache2 Licensed开源协议的HTTP库,相比u ...