水题堆2.C - Subset sequence

本文介绍了一种使用递归算法解决排列组合问题的方法,并详细解释了如何通过数学归纳法来确定特定数字的位置,最终输出指定序列的排列。
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long m,s[21];
    int n,k,i;
    s[0]=0;
    for(i=1;i<=20;i++)s[i]=(i-1)*s[i-1]+1;
    while(scanf("%d%lld",&n,&m)!=EOF){
        int f[21];
        for(i=1;i<=20;i++){
            f[i]=i;
        }
        while(m&&n){
            if(m%s[n]==0)k=m/s[n];
            else k=m/s[n]+1;
            if(k){
                printf("%d",f[k]);
                for(i=k;i<=n;i++){
                    f[i]=f[i+1];//这里用f[i]++不行
                }
                m=m-((k-1)*s[n]+1);
            }
            if(m==0)printf("\n");
                else printf(" ");
            n--;
        }
    }
    return 0;
}

n=2时集合可以根据子集的第一个数字分为两组{1},{1,2};{2},{2,1},每组有两个集合;n=3时则可以分为三组,每组有五个集合,依次类推。。。

最后可以总结出来一个公式,对于每个n=k,它的每一组中集合的个数s[k]=(k-1)*s[k-1]+1.从这里可以推出第m个数字在第几组。

对于n=k的每一组来说,因为他的首位数字固定,当去除这一组的第一个元素后,剩下的数字排列组合就像n=k-1

的所有组加起来排列组合的结果一样,只是有一位数字可能不同(刚开始做到这里的时候就不会了,想了好久可耻的看了别人的代码,结果感觉别人的方法好巧妙),就是判断第一个数字是多少后并输出后,删去这一组第一个数字,再删去这一组前面的几组,重新分析第二个数字是在n=k-1的第几组,公式 m=m-((k-1)*s[n]+1)可以得出答案,依次类推

C:\Users\龙秋林>netstat -ano -6 | findstr :1099 Displays protocol statistics and current TCP/IP network connections. NETSTAT [-a] [-b] [-e] [-f] [-i] [-n] [-o] [-p proto] [-r] [-s] [-t] [-x] [-y] [interval] -a Displays all connections and listening ports. -b Displays the executable involved in creating each connection or listening port. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. In this case the executable name is in [] at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Note that this option can be time-consuming and will fail unless you have sufficient permissions. -e Displays Ethernet statistics. This may be combined with the -s option. -f Displays Fully Qualified Domain Names (FQDN) for foreign addresses. -i Displays the time spent by a TCP connection in its current state. -n Displays addresses and port numbers in numerical form. -o Displays the owning process ID associated with each connection. -p proto Shows connections for the protocol specified by proto; proto may be any of: TCP, UDP, TCPv6, or UDPv6. If used with the -s option to display per-protocol statistics, proto may be any of: IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6. -q Displays all connections, listening ports, and bound nonlistening TCP ports. Bound nonlistening ports may or may not be associated with an active connection. -r Displays the routing table. -s Displays per-protocol statistics. By default, statistics are shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6; the -p option may be used to specify a subset of the default. -t Displays the current connection offload state. -x Displays NetworkDirect connections, listeners, and shared endpoints. -y Displays the TCP connection template for all connections. Cannot be combined with the other options. interval Redisplays selected statistics, pausing interval seconds between each display. Press CTRL+C to stop redisplaying statistics. If omitted, netstat will print the current configuration information once. C:\Users\龙秋林>
最新发布
11-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值