zoukankan      html  css  js  c++  java
  • TZOJ 4302 D1-Digit Divisibility DFS

    Using each of the digits 1, 2, 3,...,D1 exactly once to form D1 digit numbers, how many are divisible by D2.
     

    输入

     

    The input data will contain multiple cases. Each case will contain two whole numbers, D1 and D2. D1 will represent the number of unique digits (starting at 1), that will form the number. 3 <= D1 <= 9. D2 represents the divisor. 2 <= D2 <= 50.
     

    输出

     

    Each case will output the number of different D1-digit numbers that are divisible by D2 in one line.
     

    样例输入

    5  12

    4   6

    样例输出

     24

     0

    题意  用1到n组成不重复的n位数,输出能被m整除的个数。

    要点 DFS求全排列

    #include<bits/stdc++.h>
    using namespace std;
    #define MAXN 200005
    int n,vis[10],num[10],mm;
    int js;
    int DFS(int m)
    {
        if (m==n)
        {
            int sum=0;
            for (int i=0;i<m;i++)
              {
                  sum=sum*10+num[i];
              }
              if(sum%mm==0)
                  js++;
            return sum;
        }
        for (int i=1;i<=n;i++)//理解记住
        {
            if (!vis[i])
            {
            vis[i]=1;
            num[m]=i;
            DFS(m+1);
            vis[i]=0;
            }
        }
    }
    int main()
    {
        while(scanf("%d %d",&n,&mm)!=EOF)
        {
            js=0;
            memset(vis,0,sizeof(vis));
            DFS(0);
            cout<<js<<endl;
        }
    
        return 0;
    }
  • 相关阅读:
    爬取校园新闻首页的新闻
    网络爬虫基础练习
    综合练习:词频统计
    Hadoop综合大作业
    理解MapReduce
    熟悉常用的HBase操作
    熟悉常用的HDFS操作
    爬虫大作业
    数据结构化与保存
    使用正则表达式,取得点击次数,函数抽离
  • 原文地址:https://www.cnblogs.com/lhlccc/p/11567193.html
Copyright © 2011-2022 走看看