poj1850 组合数学
/*
??? n个字符长度为m的字符串个数C(n,m)
??? 因为字符串要求是升序的,所以字符确定,字符串序列也就相应确定
??? 例如,abcd四个字符长度为2的字符串个数为6,ad对应的字符串序列是ad
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NUM 27
#define LENGTH 11
int tab[NUM][NUM];
//杨辉三角
?void yanghui_table()
?{
??? int i,j;
??? memset(tab,0,sizeof(tab));
??? for(i=0; i<NUM; ++i)
??? {
??????? tab[i][0]=1;
??????? tab[i][i]=1;
??????? for(j=1; j<i; ++j)
??????? {
??????????? tab[i][j]=tab[i-1][j-1] + tab[i-1][j];
??????? }
??? }
?}
int main(int argv,char ** argvc)
{
??? int i,j,len,sum;
??? char str[LENGTH],ch;
??? yanghui_table();
??? gets(str);
??? len = strlen(str);
??? //判断是否是升序
??? for(i=1; i<len; ++i)
??? {
??????? if(str[i]<=str[i-1])
??????? {
??????????? printf("0\n");
??????????? return 0;
??????? }
??? }
??? sum = 0;
??? //求字符串长度小于str的字符串个数
??? for(i=1; i<len; ++i)
??? {
??????? sum += tab[26][i];
??? }
??? //求字符串长度等于str并在其前面的字符串个数
??? for(i=0; i<len; ++i)
??? {
??????? ch = i==0?'a':str[i-1]+1;
??????? while(ch<str[i])
??????? {
??????????? sum += tab[25+'a'-ch][len-i-1];
??????????? ch++;
??????? }
??? }
??? printf("%d\n",sum+1);
??? return 0;
}