1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 6 long long d[20][10000]; 7 8 int main() 9 { 10 char s[20]; 11 gets(s); 12 int n; 13 scanf("%d",&n); 14 memset(d,0,sizeof(d)); 15 d[0][0]=1; 16 int len=strlen(s); 17 for(int i = 1; i <= len; i++) 18 for(int j = 0; j < n; j++) 19 if( s[i-1] == ‘X‘ ) 20 for(int k = 0; k <= 9; k++){ 21 int newJ = (j*10+k)%n; 22 d[i][newJ] += d[i-1][j]; 23 } 24 else 25 { 26 int newJ = (j*10+(s[i-1]-‘0‘))%n; 27 d[i][newJ] += d[i-1][j]; 28 } 29 printf("%lld\n",d[len][0]); 30 return 0; 31 }
原文:http://www.cnblogs.com/qqky/p/6939788.html