求出给定序列的序号。有一个定理需要知道
具体看这篇博客吧http://blog.****.net/lyy289065406/article/details/6648492
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; char str[];
int ans=,C[][]; void init(void)
{
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
if(!j || i==j)
C[i][j]=;
else
C[i][j]=C[i-][j-]+C[i-][j];
C[][]=;
return;
} int main()
{
init();
while(~scanf("%s",str))
{
int len = strlen(str);
char oc = str[],nc = str[];
int ok = ;
ans=;
for(int i=;i<len;i++)
{
nc = str[i];
if(nc <= oc)
{
printf("0\n");
ok = ;
break;
}
}
if(!ok) continue; for(int i=;i<len;i++)
ans += C[][i]; for(int i=;i<len;i++)
{
char ch = i?str[i-]+:'a';
while(ch < str[i])
{
ans += C['z'-ch][len--i];
ch++;
}
}
printf("%d\n",ans+);
}
}