标签:
前面发了一个用数位DP解的题解,详见http://www.cnblogs.com/hate13/p/4452047.html
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 8566 | Accepted: 4069 |
Description
Input
Output
Sample Input
bf
Sample Output
55
Source
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define ll long long #define N 100010 ll c[27][27]; void Init() { memset(c,0,sizeof(c)); c[0][0]=1; for(int i=1;i<=26;i++) { c[i][0]=1; for(int j=1;j<=i;j++) { c[i][j]=c[i-1][j-1]+c[i-1][j]; } } } int main() { Init(); char s[12]; int len,flag; while(scanf("%s",s+1)!=EOF) { flag=1; len=strlen(s+1); for(int i=1;i<=len;i++) { if(s[i-1]>=s[i]) { flag=0; break; } } if(!flag) { printf("0\n"); continue; } ll ans=0; for(int i=1;i<len;i++) ans+=c[26][i]; for(int i=1;i<=len;i++) { char t=(i==1)?‘a‘:s[i-1]+1; while(t<s[i]) { ans+=c[‘z‘-t][len-i]; t++; } } printf("%lld\n",ans+1); } return 0; }
标签:
原文地址:http://www.cnblogs.com/hate13/p/4471212.html