zoukankan      html  css  js  c++  java
  • Light OJ 1021

    题目大意:
    给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的。
    题目解析:
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<map>
    using namespace std;
    typedef long long LL;
    const int INF = 1e9+7;
    const int maxn = 1055;
    LL dp[70000][25];///dp[状态][对k取余后的值] = 种类
    int num[20];
    char str[20];
    int main()
    {
        int T, base, K, cas = 1;
        scanf("%d", &T);
    
        while(T --)
        {
            scanf("%d %d", &base, &K);
            scanf("%s", str);
            memset(dp, 0, sizeof(dp));
            for(int i=0; str[i]; i++)
            {
                if(str[i] >= 'A' && str[i] <= 'F')
                    num[i] = str[i] - 'A' + 10;
                else
                    num[i] = str[i] - '0';
            }
    
            int n = strlen(str);
            int Lim = (1<<n) - 1;
    
            dp[0][0] = 1;
            for(int i=1; i<=Lim; i++)///每种状态
            {
                for(int j=0; j<n; j++)///判断这种状态的数字是否存在
                {
                    if( (i&(1<<j)) )
                    {
                        int newSta = i - (1<<j);
                        for(int k=0; k<K; k++)
                        {
                            int p = (k*base + num[j])%K;
                            dp[i][p] += dp[newSta][k];
                        }
                    }
                }
            }
            printf("Case %d: %lld
    ",cas++, dp[Lim][0]);
    
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    Problem S: 分数类的模板数组类
    Problem E: 向量的运算
    Problem D: 强悍的矩阵运算来了
    Problem C: Person类与Student类的关系
    Problem B: 还会用继承吗?
    Problem A: 求个最大值
    Problem B: 数组类(II)
    树的直径题集
    LCA题集
    线段树总结
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4905557.html
Copyright © 2011-2022 走看看