POJ 1850 Code
2014-03-16 22:55
232 查看
//这题和上题没什么区别 // 就是数据大了点而已 // 直接参考上题 /article/6726501.html #include <iostream> #include <string> #include<sstream> #include <cmath> #include <map> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define LL long long LL C[40][40]; int dp[40]; void init() { int i,j; for(i=0;i<=30;i++) C[i][0]=1; for(i=1;i<=30;i++) for(j=1;j<=i;j++) C[i][j]=C[i-1][j-1]+C[i-1][j]; } char str[10]; int h[30]; LL fun(int ln,int index) { int i=1,j=1; LL sum=0; char c=str[index]; int lf=26; if(index>0) { index--; lf='z'-str[index]; i=str[index]-'a'+1; } for(;i<=26;i++) if(!h[i]) { if(c==(i-1+'a')) break; else { sum=sum+ C[lf-j][ln-1]; j++; } } return sum; } int main() { init(); int i,j; while(scanf("%s",str)!=EOF) { memset(h,0,sizeof(h)); int len=strlen(str); int flag=0; LL ans=0; for(i=1;i<len;i++) ans+=C[26][i]; for(i=0;i<len;i++) for(j=i+1;j<len;j++) if(str[i]>=str[j]) flag=1; if(flag) printf("0\n"); else { for(i=0;i<len;i++) { ans=ans+fun(len-i,i); h[str[i]-'a'+1]=1; // lf--; } printf("%lld\n",ans+1); } } return 0; }
相关文章推荐
- POJ1850——Code(组合数)
- poj1850--Code(组合篇2)
- 【poj 1850】Code 题意&题解&代码(C++)
- POJ 1850 Code 统计问题
- POJ 1850Code(组合数学)
- POJ 1850 Code
- poj 1850 Code
- [POJ 1850] Code
- poj 1850 Code
- poj 1850 Code
- POJ - 1850 Code(组合数学推公式)
- poj 1850 Code
- POJ1850——Code
- [poj 1850] Code 组合数学
- POJ 1850 Code
- poj 1850 Code 1496 Word Index
- poj 1850 code
- POJ 1850 Code(排列数组)
- POJ 1850 Code 组合数学
- poj 1850 Code