Cod sursa(job #1263992)

Utilizator Kira96Denis Mita Kira96 Data 15 noiembrie 2014 14:07:35
Problema Ratphu Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include<fstream>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#define FIT(a,b) for(vector<int>::iterator a=b.begin();a!=b.end();a++)
#include<stack>
#define ROF(a,b,c) for(long long a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(long long a=b;a<=c;++a)
#define REP(a,b) for(register int a=0;a<b;++a)
#include<cstring>
#include<bitset>
#include<cmath>
#include<iomanip>
#include<queue>
#define debug cerr<<"OK";
#define pii pair<int,int>
#define f cin
#define g cout
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define N 10100
#define SQ 350
using namespace std;
/*ifstream f("a.in");
ofstream g("a.out");*/
/*int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};*/
int cif[30],n,p,lim,t;
long long D[1<<20][21];
int main ()
{
	freopen("ratphu.in","r",stdin);
	freopen("ratphu.out","w",stdout);

	f>>n>>p;
	while(n)
    {
        cif[++t]=n%10;
        n/=10;
    }
    D[0][0]=1;
    lim=1<<t;
    --lim;
    FOR(r,0,p-1)
    FOR(i,0,lim)
    for(int j=1,t=1;j<=lim;j<<=1,++t)
        if(!(i&j))
            D[i|j][(r*10+cif[t])%p]+=D[i][r];
    g<<D[lim][0];
	return 0;
}
//Look at me! Look at me! The monster inside me has grown this big!