组合数学!!!
详情见:http://hi.baidu.com/lxyzmnwvhokptur/item/18c806469a668fe31e19bc1a#0
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #include<iomanip> 5 #include<cmath> 6 #include<cstring> 7 #include<vector> 8 #define ll __int64 9 #define pi acos(-1.0) 10 #define MAX 50000 11 using namespace std; 12 char a[10]; 13 int C(int n,int m){ 14 int sum =1; 15 for (int i=n;i>n-m;i--) sum*=i; 16 for (int j=1;j<=m;j++) sum /=j; 17 return sum; 18 } 19 int main(){ 20 int i,j,len,sum; 21 while(cin>>a){ 22 sum=0; 23 len = strlen(a); 24 if (len == 1){ 25 if (a[0]>='a'&&a[0]<='z') 26 cout<<a[0]-'a'+1<<endl; 27 else cout<<0<<endl; 28 continue; 29 } 30 for (i=1;i<len;i++){ 31 if (a[i]<=a[i-1]) 32 break; 33 } 34 if (i!=len){ 35 cout<<0<<endl; 36 continue; 37 } 38 for (i=1;i<len;i++) 39 sum += C(26,i); 40 for (j=1;j<a[0]-'a'+1;j++) 41 sum += C(26-j,len-1); 42 for (i=1;i<len;i++){ 43 for (j=a[i-1]+2-'a';j<a[i]-'a'+1;j++) 44 sum += C(26-j,len-i-1); 45 } 46 cout<<++sum<<endl; 47 } 48 return 0; 49 }