Cod sursa(job #1264007)

Utilizator Kira96Denis Mita Kira96 Data 15 noiembrie 2014 14:18:32
Problema Ratphu Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.45 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(int a=b;a>=c;--a)
#include<vector>
#include<algorithm>
#define FOR(a,b,c) for(int 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],p,lim,t;
long long n,D[21][1<<20];
int main ()
{
	freopen("ratphu.in","r",stdin);
	freopen("ratphu.out","w",stdout);

	f>>n>>p;
	t=-1;
	while(n)
    {
        cif[++t]=n%10;
        n/=10;
    }
    D[0][0]=1;
    lim=1<<(t+1);
    --lim;

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