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