E - 1sting (递推+大数加法)
来源:互联网 发布:天猫淘宝棉拖鞋 编辑:程序博客网 时间:2024/04/30 21:54
根据题意递推构造类fibnacci数列,由于要算到第200项,已经远远超出long long 所能表示的范围。
要用大数加法。即用数组模拟。
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
311111111
Sample Output
128
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;typedef long long ll;char s[210];char f[210][210];char s1[210],s2[210];void init(){ int l1,l2; memset(f,0,sizeof(f)); strcpy(f[1],"1"); strcpy(f[2],"2"); strcpy(f[3],"3"); for(int k=4;k<=200;k++) { strcpy(s1,f[k-1]); strcpy(s2,f[k-2]); l1 = strlen(s1); l2 = strlen(s2); int i=0,c = 0,x = 0; while(i<l1 && i<l2) { int t = s1[i]-'0'+s2[i]-'0'+c; if(t>=10) { c = t/10; //这里不是简单的c=1 f[k][x++] = t%10+'0'; } else { f[k][x++] = t+'0'; c = 0; //这里忘记清0 } i++; } while(i<l1) { if(c) { int t = (s1[i]-'0'+c); f[k][x++] = t%10+'0'; i++; c = t/10; } else f[k][x++] = s1[i++]; } while(i<l2) { if(c) { int t = (s2[i]-'0'+c); f[k][x++] = t%10+'0'; i++; c = t/10; } else f[k][x++] = s2[i++]; } if(c) f[k][x++] = c+'0'; }}int main(){ int T; init(); scanf("%d",&T); while(T--) { scanf("%s",s); int len = strlen(s); int p = strlen(f[len]); for(int i=p-1;i>=0;i--) printf("%c",f[len][i]); printf("\n"); } return 0;}
0 0
- E - 1sting (递推+大数加法)
- 【hdoj_1865】1sting(递推+大数)
- 1sting(JAVA大数+ 递推)
- hdu 1865 1sting (java大数&递推)
- 【杭电oj】1865 - 1sting(大数递推)
- 大数加法(递推)
- POJ 1090 Chain 递推 + 大数加法
- poj 2506 Tiling 《大数加法+递推》
- 【递推DP】HDU1865-1sting
- hdu1865大数 1sting
- hdu1865 1 sting(大数)
- HDOJ 1865 1sting 13.04.21 周赛结题报告 (大数加法)
- HDU 1865 1sting(大数斐波那契数列,模拟加法)
- HDU 1865 1sting 斐波那契数列 + 大数加法
- 1sting(大数递归)
- poj 2506 Tiling(递推+大数加法)
- hdu 1297 Children’s Queue (大数加法+递推)
- HDU 1250 Hat's Fibonacci(递推+大数加法)
- 【Github教程】史上最全github使用方法:github入门到精通
- Sort Colors
- 【基础练习】【模拟】Uva489 - Hangman Judge题解
- ⑩--Foundation框架基础
- 20150117学习总结
- E - 1sting (递推+大数加法)
- 32位汇编语言学习笔记(45)--测试简单文件操作接口(完)
- Linux Barrier IO
- HDU1864 01背包
- 什么时候使用存储过程比较适合?
- leetcode-valid parenthesses
- jenkins持续构建
- Android颜色配置表
- Linux 之-------Shell 程序的建立和特殊字符