zoukankan      html  css  js  c++  java
  • codeforces #235div2 D

    完全没看出是状态压缩DP,

    果然没练习,之前一直再看,看来要把状压做几道了,

    上代码吧:代码也是问道的

    无语。。。

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    typedef long long ll;
    using namespace std;

    int num[11], val[11];

    ll dp[60000][100];

    int main()
    {
        ll n;
        int m;
        cin >> n >> m;
        while (n)
        {
            num[n % 10]++;
            n /= 10;
        }
        val[0] = 1;
        for (int i = 1; i <= 10; i++)
            val[i] = val[i - 1] * (num[i - 1] + 1);
        dp[0][0] = 1;
        for (int i = 0; i < val[10]; i++)
            for (int j = 0; j < 10; j++)
            {
                if (j == 0 && i < val[1])
                    continue;
                if (i / val[j] % (num[j] + 1) >= num[j])
                    continue;
                for (int k = 0; k < m; k++)
                    dp[i + val[j]][(10 * k + j) % m] += dp[i][k];
            }
        cout << dp[val[10] - 1][0] << endl;
        return 0;

    } 

  • 相关阅读:
    Sum Root to Leaf Numbers
    Sum Root to Leaf Numbers
    Sort Colors
    Partition List
    Binary Tree Inorder Traversal
    Binary Tree Postorder Traversal
    Remove Duplicates from Sorted List II
    Remove Duplicates from Sorted List
    Search a 2D Matrix
    leetcode221
  • 原文地址:https://www.cnblogs.com/forgot93/p/3595397.html
Copyright © 2011-2022 走看看