【递推DP】HDU1865-1sting
来源:互联网 发布:标的物 知乎 编辑:程序博客网 时间:2024/05/21 09:08
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1865
Problem 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
递推DP代码:
#include<iostream>using namespace std;// 状态转移方程:// dp[i]=d[i-1]+dp[i-2];const int maxn=205;string dp[maxn]="";string add(string a,string b){ string ans=""; int aa[maxn]={0},bb[maxn]={0}; int aLen=a.size(); int bLen=b.size(); int maxLen=max(aLen,bLen); for(int i=0;i<aLen;i++) aa[aLen-i-1]=a[i]-'0'; for(int i=0;i<bLen;i++) bb[bLen-i-1]=b[i]-'0'; for(int i=0;i<maxLen;i++){ aa[i]+=bb[i]; aa[i+1]+=aa[i]/10; aa[i]%=10; } if(aa[maxLen]) maxLen++; for(int i=maxLen-1;i>=0;i--) ans+=aa[i]+'0'; return ans;}void faction(){ dp[0]="1"; dp[1]="1"; for(int i=2;i<=200;i++) dp[i]=add(dp[i-1],dp[i-2]);}int main(){ int t,n; string str; cin.sync_with_stdio(false); faction(); cin>>t; while(t--){ cin>>str; n=str.size(); cout<<dp[n]<<endl; } return 0;}
0 0
- 【递推DP】HDU1865-1sting
- hdu1865 1sting
- hdu1865大数 1sting
- hdu1865 1 sting(大数)
- HDU1865 1sting
- E - 1sting (递推+大数加法)
- 【hdoj_1865】1sting(递推+大数)
- 1sting(JAVA大数+ 递推)
- hdu 1865 1sting (java大数&递推)
- 【杭电oj】1865 - 1sting(大数递推)
- hdu1865
- hdu1865
- 1sting
- 1sting
- 1sting
- 1sting
- 1sting
- 1sting
- oracle中的sql%rowcount,sql%found、sql%notfound、sql%rowcount和sql%isopen
- Druid、BoneCP、DBCP、C3P0等主流数据库对比(本文完全转载)
- MySQL中的alter table命令的基本使用方法及提速优化
- 证书生成 和Tomcat配置
- 【数据结构】树状数组笔记
- 【递推DP】HDU1865-1sting
- Windows下递归搜索文件及其所在目录 .bat脚本实现
- MySQL 服务正在启动。MSQL服务无法启动。服务没有报告任何错误 的解决办法
- uva10328 Coin Toss(dp)
- Mybatis自动生成Xml文件,针对字段类型为text等会默认产生XXXXWithBlobs的方法问题
- 泳道图怎么画?
- div做出一个模糊效果的背景、
- windows下mysql数据库主从复制
- tips