虽然有点水,不过做完还是有收获的
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define MC(a,b) memcpy(a,b,sizeof(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxc = 27;
const int maxn = 11;
i64 c[maxc][maxc];
i64 dp[maxn][maxc];
i64 f[maxn];
string s;
void init()
{
MM(c,0);
for(int i=0;i<maxc;i++)
{
c[i][0]=1;
c[i][i]=1;
}
for(int i=1;i<maxc;i++)
{
for(int j=1;j<i;j++)
{
c[i][j]=c[i-1][j-1]+c[i-1][j];
}
}
MM(dp,0);
for(int i=1;i<maxn;i++)
{
dp[i][0]=0;
}
for(int i=1;i<maxn;i++)
{
for(int j=1;j<26;j++)
{
dp[i][j]=c[26-j][i-1];
}
}
MM(f,0);
for(int i=1;i<maxn;i++)
{
f[i]=c[26][i];
}
for(int i=1;i<maxn;i++)
{
f[i]+=f[i-1];
}
return ;
}
i64 start()
{
int len = s.length();
int pre,now,pos;
i64 ans=1;
for(int i=len-1;i>=1;i--)
{
pos = len - i;
pre = s[i-1]-'a';
now = s[i]-'a';
for(int x=now;x>pre+1;x--)
{
ans+=dp[pos][x];
}
}
now = s[0]-'a';
for(int i=now;i>=1;i--)
{
ans+=dp[len][i];
}
ans+=f[len-1];
return ans;
}
bool can()
{
int temp=-inf;
for(int i=0;i<s.length();i++)
{
if(s[i]>temp && s[i]>='a' && s[i]<='z')
{
temp = s[i];
}
else
{
return false;
}
}
return true;
}
int main()
{
init();
while(cin>>s)
{
if(can())
{
cout<<start()<<endl;
}
else
{
cout<<"0"<<endl;
}
}
return 0;
}
分享到:
相关推荐
北大POJ1850-Code 解题报告+AC代码
poj 1780 Code.md
POJ Code Submitter V1.2 (Build 1012)版本更新: 1.修复了初次使用报错的问题 2.修复了长时间无操作重新验证身份失败的问题 3.修复了登录界面可以键入非法字符的BUG 4.修复了登录界面键入新用户名时,密码框不清空...
C + + language learning poj100 question bank and code
这是北京大学ACM也就是POJ2195的源代码,用的是最优匹配算法。
poj1002 source code input: The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on ...
POJ3259--Wormholes,使用bellman方法。
poj 上的几道kmp 题的解题报告 sourse code of kmp algorithm
this is an sample of the pku judge online code. poj 1433
acm code of 20053565 poj onlinejudge 高精度 DP 图论 算法 最大流 最小生成树 线段树
leetcode杯 algorithm leetcode模块下含所有做的leetcode的题 其中包命名规则为code_年份_月份_日期_(前期无,后期[compet->...poj_lanqiao模块下含在poj和蓝桥杯网站上做的题 附上博客地址 版权:copyright:zhangjingao
一些poj上的ac代码,不是自己的, 是别人的
1.2.1 世界规模的大赛——Google Code Jam(GCJ) 1.2.2 向高排名看齐!——TopCoder 1.2.3 历史最悠久的竞赛—— ACM-ICPC 1.2.4 面向中学生的信息学奥林匹克竞赛——JOI-IOI 1.2.5 通过网络自动评测——Online ...
我的解决方案代码适用于流行的在线裁判系统,例如 POJ、HDOJ、SGU 和 ACM-ICPC Live Archive。 但是,我忘记了我用来解决这些问题的算法! 我将通过竞赛来组织代码和解决方案。 一些索引页面将可用,以便您可以更快...
Judge-题库中有大量的题目-【北京大学】-【多语言版】【POJ】 http://poj.org Sphere Online Judge-允许使用各种各样的编程语言【SPOJ】 http://www.spoj.pl/ SGU Online Contester-具有模拟参加历史比赛的...
vs2013下的工程文档,是poj昂贵的聘礼的源码,需要的朋友可以下载看看
leetcode中国 《算法竞赛进阶指南》练习代码 《算法竞赛进阶指南》全部例题和习题的练习代码...【POJ 1958】Strange Towers of Hanoi 增强汉诺塔 Accepted 2018.07.23 【BZOJ 1218】激光炸弹 二维前缀和 Accepted 2018.
leetcode 和 oj OJ - 掌握解决问题的方法、算法和数据结构 ...POJ:ACM ZOJ:ACM UVA OJ:ACM SGU OJ:ACM Project Euler:mathematics Timus Online Judge hackerearth 算法竞赛 ACM Topcoder Google Code Jam Codeforces
POJ-QDUOJ-SPOJ-Timus-Toph-URI在线法官-USACO-USACO培训-UVa在线法官-虚拟法官-Yandex竞赛解析器可用于以下网站:-AtCoder-百joon在线法官-CodeChef-Codeforces-COJ-CSU-ACM在线法官-DevSkill-DMOJ-E-Olymp-ECNU...
leetcode oj和leetcode ...通过在一些OJ网站上做的题,主要是UVa和POJ. 都是刘汝佳《算法竞赛入门经典》上的例题,强烈推荐《算法竞赛入门经典》系列丛书. Talk is cheap. Show me the code. --Linus