数字全排列
Sample Input
3 132
Sample Output
2
#include<stdio.h>
long f(long n){return n<=2?n:n*f(n-1);}
int main()
{
long n,k,i,t=0,sum=1,a[9],b[10]={0},r;
scanf("%d %d",&n,&k);
while(k)a[t++]=k%10,k/=10;
t--;
while(t>=0)
{
r=1;
for(i=1;i<=n;i++)
if(b[i]==0)
if(i<a[t])r++;
else if(i==a[t])break;
sum+=(r-1)*f(t),b[a[t]]++;
t--;
}
printf("%d\n",sum);
return 0;
}