Look at the data range ... This is not violence ...
O (15 * 2 ^ 10 * 10) It's easy to get through.
-----------------------------------------------------------------
#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x)) using namespace std;const int MAXN = one;const int MUL[10] = {1, ten, +, +, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};int MOD, NUM[MAXN], CNT, T[MAXN];void init () {cnt = 0;char C = getchar ();For (;!isdigit (c); c = GetChar ());For (; IsDigit (c); c = GetChar ())num[cnt++] = C-' 0 ';scanf ("%d", &mod);}int work () {int ans = 0;sort (num, num + cnt);Rep (i,cnt) t[i] = mul[i]% MOD;Do {int m = 0;Rep (i, CNT)m = (M + num[i] * t[i])% MOD;if (!m) ans++;} while (Next_permutation (num, num + cnt));return ans;}int main () {freopen ("test.in", "R", stdin);int t;scanf ("%d", &t);While (t--) {init ();printf ("%d\n", Work ());}return 0;}
-----------------------------------------------------------------
1072: [SCOI2007] Arrange perm time limit: Sec Memory Limit: 162 MB
Submit: 1211 Solved: 751
[Submit] [Status] [Discuss] Description
Given a number string s and a positive integer d, the statistic S has how many different permutations can be divisible by D (can have a leading 0). For example 123434 there are 90 kinds of permutations can be divisible by 2, of which the lowest of 2 has 30 species, the bottom of 4 has 60.
Input
The input first line is an integer t, which indicates the number of test data, each of the following sets of S and D, separated by a space. The S guarantee contains only the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Output
Only one row per data, indicating the number of permutations that can be divisible by D.
Sample Input7
000 1
001 1
1234567890 1
123434 2
1234 7
12345 17
12345678Sample Output1
3
3628800
90
3
6
1398HINT
In the first three examples, the permutations are 1, 3, and 3628800, each of which is a multiple of 1.
Limit
100% of the data satisfies: s is not longer than ten, 1<=d<=1000, 1<=t<=15
Source
Bzoj 1072: [SCOI2007] Arrange perm ()