惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - Amonw's Weblog

.NET默认一个客户端对同一个服务器地址同时只能建立2个TCP连接 homekit2mqtt on DietPi .Net Trace->Listeners->Remove Oracle 12c client with .NET legacy Oracle driver Minimum setup for Apache+AD SSO Minimum configuration for openldap to proxy multiple AD into a single search base Make Notepad++ auto close HTML/XML tags after the slash(the Dreamweaver way) ASDM through site to site VPN - Amonw's Weblog PHP, LDAPS and Apache DFS security warning and use group policy to set up internet security zones Refresh recovery area usage data after manually deleting files under recovery area Create Oracle Enterprise Manager repository data after restore a database from another server Restore Oracle database to another server .PRT extension and multiple NX versions Fix network adapter not present problem in cloned CentOS NX 8.5 License Server Firewall Setting Cisco ASA intra-interface routing How to configure windows machine to allow file sharing with dns alias (CNAME) Install unifi controller on CentOS
排列组合算法(PHP)
Amonw's Weblog · 2016-06-20 · via 博客园 - Amonw's Weblog

用php实现的排列组合算法。使用递归算法,效率低,胜在简单易懂。可对付元素不多的情况。

//从$input数组中取$m个数的组合算法
function comb($input, $m)
{
    if($m==1)
    {
        foreach($input as $item)
        {
            $result[]=array($item);
        }
        return $result;
    }
    for($i=0;$i<=count($input)-$m;$i++)
    {
        $nextinput=array_slice($input,$i+1);
        $nextresult=comb($nextinput,$m-1);
        foreach($nextresult as $one)
        {
            $result[]=array_merge(array($input[$i]),$one);
        }
    }
    return $result;
}

//从$input数组中取$m个数的排列算法
function perm($input,$m)
{
    if($m==1)
    {
        foreach($input as $item)
        {
            $result[]=array($item);
        }
        return $result;
    }
    for($i=0;$i<count($input);$i++)
    {
        $nextinput=array_merge(array_slice($input,0,$i),array_slice($input,$i+1));
        $nextresult=perm($nextinput,$m-1);
        foreach($nextresult as $one)
        {
            $result[]=array_merge(array($input[$i]),$one);
        }
    }
    return $result;
}

$input=array(1,2,3,4,5);
print_r(comb($input,3));
print_r(perm($input,3));