ANARC05H - Chop Ahoy! Revisited!

Given a non-empty string composed of digits only, we may group these digits into sub-groups (but maintaining their original order) if, for every sub-group but the last one, the sum of the digits in a sub-group is less than or equal to the sum of the digits in the sub-group immediately on its right. Needless to say, each digit will be in exactly one sub-group.

For example, the string 635 can only be grouped in one sub-group [635] or in two sub-groups as follows: [6-35] (since 6 < 8.) Another example is the string 1117 which can be grouped in one sub-group [1117] or as in the following: [1-117], [1-1-17], [1-11-7], [1-1-1-7], [11-17] and [111-7] but not any more, hence the total number of possibilities is 7.

Write a program that computes the total number of possibilities of such groupings for a given string of digits.

Input

Your program will be tested on a number of test cases. Each test case is specified on a separate line. Each line contains a single string no longer than 25, and is made of decimal digits only.

The end of the test cases is identified by a line made of the word "bye" (without the quotes.) Such line is not part of the test cases.

Output

For each test case, write the result using the following format:

k. n

where k is the test case number (starting at 1,) and n is the result of this test case.

Example

Input:
635
1117
9876
bye Output:
1. 2
2. 7
3. 2
f[i][j]表示进行到第i位,且最后一个集合包含j个数字的方案个数,显然f[i][j]=SUM{f[i-j][k] | 只要最后i的最后j个数的和>=i-j的最后k个数的和就能转移}
 #include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int main()
{
char s[];
int x[]={};
int f[][];
int i,j,k,cas=;
while(scanf("%s",s+)){
if(!strcmp(s+,"bye")) break;
int n=strlen(s+);
for(i=;i<=n;++i){
x[i]=x[i-]+s[i]-'';
}
memset(f,,sizeof(f));
f[][]=f[][]=;
for(i=;i<=n;++i){
for(j=;j<=i;++j){
if(i==j) f[i][j]=;
else f[i][j]=;
for(k=;k<=i-j;++k){
if(x[i]-x[i-j]>=x[i-j]-x[i-j-k])
f[i][j]+=f[i-j][k];
}
}
}
int s=;
for(i=;i<=n;++i) s+=f[n][i];
cout<<++cas<<". "<<s<<endl;
}
return ;
}

最新文章

  1. Python-类的属性
  2. Jquery实现兼容各大浏览器的Enter回车切换输入焦点的方法
  3. Hibernate 知识点梳理
  4. windows phone 豆瓣api的封装
  5. ios开发--集成银联3.3.0
  6. MySQL中DATE_FORMATE函数内置字符集解析
  7. 让自己的C++程序(非服务程序)运行为一个windows service
  8. Qt之Windows资源文件(.rc文件)
  9. Advanced Fruits(好题,LCS的模拟)
  10. [LeetCode] My Calendar II 我的日历之二
  11. [TJOI 2017]可乐
  12. asp.net 下的中文分词检索工具 - jieba.net
  13. 再会Java
  14. NodeJS中的require和import
  15. 互联网校招面试必备——Java多线程
  16. 牛客红包OI赛 C 小可爱表白
  17. 【Struts2学习笔记(9)】单文件上传和多文件上传
  18. IT小小鸟读后感言
  19. 代理模式 静态代理、JDK动态代理、Cglib动态代理
  20. C#实现文件上传以及文件下载

热门文章

  1. 安卓和ios的区别
  2. SVN无法Cleanup
  3. Winter-2-STL-A Argus 解题报告及测试数据
  4. 如何通过包名打开手机里的APP
  5. 吉哥系列故事——完美队形I
  6. web.xml servlet、servlet-mapping配置
  7. 20144303 《Java程序设计》第九周学习总结
  8. MiniTools在ubuntu下快捷方式
  9. 【前端】用javaScript实现实现一个球池的效果
  10. mysql数据库无法连接(JDBC)java.net.ConnectException: Connection timed out