题目链接:http://acm.hust.edu.cn/vjudge/contest/121397#problem/F

http://acm.hdu.edu.cn/showproblem.php?pid=1865

Description

You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get. 

Input

The first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200. 

Output

The output contain n lines, each line output the number of result you can get . 
 
Sample Input

Sample Output

AC代码:

 #include <stdio.h>
#include <string.h>
#define maxn 300
int str1[maxn][maxn];
int main()
{
int T, i, j;
scanf("%d ",&T); while(T--)
{
char str[];
gets(str); int len=strlen(str);
str1[][]=;
str1[][]=; for(i=;i<len;i++)
{
int c=,k;
for(k=;k<maxn;k++)
{
int s=str1[i-][k]+str1[i-][k]+c;
str1[i][k]=s%;
c=s/;
}
while(c)
{
str1[i][k++]=c%;
c/=;
}
} for(i=;i>=;i--)
if(str1[len-][i])
break; for(j=i;j>=;j--)
printf("%d",str1[len-][j]);
printf("\n");
}
return ;
}

A完还A:

 #include<stdio.h>
#include<string.h> #define N 210
int f[][N]; void init()
{
int i, j;
f[][] = ;
f[][] = ; for(i = ; i <= ; i++)
for(j = ; j <= ; j++)
{
f[i][j] += f[i-][j] + f[i-][j];
if(f[i][j] >= )
{
f[i][j] -= ;
f[i][j+]++;
}
}
} int main()
{ int i, j, t;
char s[N]; scanf("%d", &t);
init(); while(t--)
{
scanf("%s", s); int n = strlen(s); int k = ;
for (; f[n][k] == ; k--);
for (; k >= ; k--)
printf ("%d",f[n][k]); printf("\n"); } return ;
}

最新文章

  1. async &amp; await 的前世今生(Updated)
  2. Swift3.0P1 语法指南——控制流
  3. Android之UI编程(一):线性布局
  4. MySQL 在 LIMIT 条件后注入
  5. URL传递中文乱码的问题
  6. hud 2602 Bone Collector
  7. 在windows环境下,为什么要用Notepad++编辑?
  8. dd命令使用详解
  9. WPF制作子窗体的弹出动画效果
  10. jQuery 核心 - noConflict() 方法,jQuery 文档操作 - detach() 方法
  11. 旧书重温:0day2【3】 详细解读PEB法 查找kener32地址
  12. 解放程序猿宝贵的右手(或者是左手) ——Android自动化测试技巧
  13. 70个经典的 Shell 脚本面试问题
  14. Apache Solr vs Elasticsearch
  15. c/c++链队列
  16. 初入MEF-IOC导入导出
  17. python中安装request模块
  18. hdu 6161--Big binary tree(思维--压缩空间)
  19. 牛客网校招全国统一模拟笔试(三月场)- Java方向
  20. vue之v-if和v-show

热门文章

  1. A - 小Y上学记——修学分
  2. iptables指令参考
  3. android 常用
  4. android 线程池的使用
  5. android:layout_weight属性的使用方法总结
  6. test错误记录
  7. java类的初始化
  8. POJ 1611 The Suspects(简单并查集)
  9. Git 删除文件
  10. find the closest sum to a target value