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;
    }
  • 相关阅读:
    oracle学习13
    oracle学习12
    oracle学习11
    oracle学习10
    CodeForces
    CodeForces
    UVA
    poj3320 Jessica's Reading Problem
    poj2456 Aggressive cows
    jQuery 鼠标滚轮插件 mousewheel
  • 原文地址:https://www.cnblogs.com/lhlccc/p/11567193.html
Copyright © 2011-2022 走看看