Codeforces Round #235 (Div. 2) D. Roman and Numbers(状压dp)_html/css_WEB-ITnose

WBOY
Freigeben: 2016-06-24 11:52:00
Original
918 Leute haben es durchsucht

Roman and Numbers

time limit per test

4 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m.

Number x is considered close to number n modulo m, if:

  • it can be obtained by rearranging the digits of number n,
  • it doesn't have any leading zeroes,
  • the remainder after dividing number x by m equals 0.
  • Roman is a good mathematician, but the number of such numbers is too huge for him. So he asks you to help him.

    Input

    The first line contains two integers: n (1?≤?n?1018) and m (1?≤?m?≤?100).

    Output

    In a single line print a single integer ? the number of numbers close to number n modulo m.

    Sample test(s)

    input

    104 2
    Nach dem Login kopieren

    output

    input

    223 4
    Nach dem Login kopieren

    output

    input

    7067678 8
    Nach dem Login kopieren

    output

    47
    Nach dem Login kopieren

    Note

    In the first sample the required numbers are: 104, 140, 410.

    In the second sample the required number is 232.


    题意:给出一个数字num和m,问通过重新排列num中的各位数字中有多少个数(mod m)=0,直接枚举全排列肯定不行,可以用状压dp来搞..

    dp[S][k]表示选了num中的S且(mod m)=k的方案种数,初始条件dp[0][0]=1,转移方为dp[i|1

    #include <iostream>#include <cstring>using namespace std;typedef long long ll;ll dp[1>num>>m) {		memset(dp,0,sizeof dp);		memset(c,0,sizeof c);		dp[0][0]=1;		ll div=1,sz=strlen(num),t=1  <br>  <p></p>  <p><br> </p> </cstring></iostream>
    Nach dem Login kopieren
    Quelle:php.cn
    Erklärung dieser Website
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
    Beliebte Tutorials
    Mehr>
    Neueste Downloads
    Mehr>
    Web-Effekte
    Quellcode der Website
    Website-Materialien
    Frontend-Vorlage
    Über uns Haftungsausschluss Sitemap
    Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!