http://poj.org/problem?id=2506

题意:

思路:
递推。a[i]=a[i-1]+2*a[i-2]。

计算的时候是大整数加法。错了好久,忘记考虑1了...晕倒。

 #include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std; int n;
char s[][]; void cacl(int i)
{
int k;
int len1 = strlen(s[i - ]);
int len2 = strlen(s[i - ]);
int flag = ;
for (k = ; k < len2; k++)
{
int x = s[i - ][k] - '' + * (s[i - ][k] - '');
if (flag)
{
x += flag;
flag = ;
}
if (x>)
{
flag = x / ;
x = x % ;
}
s[i][k] = x + '';
}
while (k < len1)
{
int x = s[i - ][k] - '';
if (flag)
{
x += flag;
flag = ;
}
if (x>)
{
flag = x / ;
x = x % ;
}
s[i][k] = x + '';
k++;
}
if (flag) s[i][k] = flag + '';
} void init()
{
s[][] = '';
s[][] = '';
s[][] = '';
for (int i = ; i <= ; i++)
cacl(i);
} int main()
{
init();
while (cin>>n)
{
int m = strlen(s[n]);
for (int i = m-; i >= ; i--)
cout << s[n][i];
cout << endl;
}
}

POJ 2506 Tiling(递推+大整数加法)的更多相关文章

  1. poj 2506 Tiling 递推

    题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...

  2. POJ 2506 Tiling (递推 + 大数加法模拟 )

    Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7965   Accepted: 3866 Descriptio ...

  3. PKU 2506 Tiling(递推+高精度||string应用)

    题目大意:原题链接有2×1和2×2两种规格的地板,现要拼2×n的形状,共有多少种情况,首先要做这道题目要先对递推有一定的了解.解题思路:1.假设我们已经铺好了2×(n-1)的情形,则要铺到2×n则只能 ...

  4. (递推 大整数) Children’s Queue hdu1297

    Children’s Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. 2981:大整数加法-poj

    2981:大整数加法 总时间限制:  1000ms 内存限制:  65536kB 描述 求两个不超过200位的非负整数的和. 输入 有两行,每行是一个不超过200位的非负整数,可能有多余的前导0. 输 ...

  6. AC日记——大整数加法 openjudge 1.6 10

    10:大整数加法 总时间限制:  1000ms 内存限制:  65536kB 描述 求两个不超过200位的非负整数的和. 输入 有两行,每行是一个不超过200位的非负整数,可能有多余的前导0. 输出 ...

  7. HDU1002——大整数加法

    题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...

  8. openjudge计算概论-大整数加法

    /*=====================================================================1004:大整数加法总时间限制: 1000ms 内存限制: ...

  9. A——大整数加法(HDU1002)

    题目: I have a very simple problem for you. Given two integers A and B, your job is to calculate the S ...

随机推荐

  1. 004-redis-命令-哈希操作,列表操作

    Redis hash 命令 下表列出了 redis hash 基本的相关命令: 序号 命令及描述 1 HDEL key field1 [field2] 删除一个或多个哈希表字段 2 HEXISTS k ...

  2. 十天精通CSS3(2)

    圆角效果 border-radius border-radius是向元素添加圆角边框. 使用方法: border-radius:10px; /* 所有角都使用半径为10px的圆角 */ border- ...

  3. ZOJ:2833 Friendship(并查集+哈希)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2833 A friend is like a flower, a rose ...

  4. openstack 部署笔记--keystone

    控制节点 安装keystone包 # yum install openstack-keystone httpd mod_wsgi keystone配置文件 # vim /etc/keystone/ke ...

  5. 获取Let`s Encrypt证书的三种方式

    1,acme.sh 方式 1)获取acme脚本 curl https://get.acme.sh | sh 2)开始获取证书 acme.sh强大之处在于,可以自动配置DNS,不用去域名后台操作解析记录 ...

  6. 软件包管理:yum在线管理-yum命令

    只要我们的电脑可以接入互联网,那么yum源就是配好的,yum命令可以直接使用. 列出的是服务器上全部的rpm包. 包名,包全名的概念只在rpm手动管理时有用. 关键字主要指包名,只要知道了关键字就可以 ...

  7. Java线程基础知识(状态、共享与协作)

    1.基础概念 CPU核心数和线程数的关系 核心数:线程数=1:1 ;使用了超线程技术后---> 1:2 CPU时间片轮转机制 又称RR调度,会导致上下文切换 什么是进程和线程 进程:程序运行资源 ...

  8. python在交互模式下直接输入对象后回车,调用的是对象的__repr__()方法,这个方法表示的是一个编码,用print+对象是调用对象的__str__方法

    交互模式下调用对象的__repr__()方法,这个方法表示的是一个编码 >>> u"国庆节快乐"u'\u56fd\u5e86\u8282\u5feb\u4e50' ...

  9. python类方法、静态方法、实例方法例子

    类方法,静态方法,普通方法 #coding=utf-8   class Foo:     def __init__(self,name):         self.name=name       d ...

  10. python管道pipe,两个进程,使用管道的两端分别执行写文件动作,带锁(lock)

    #coding=utf-8import multiprocessing as mp def write_file(content,lock):    lock.acquire()    with op ...