Problem 1147 Tiling

Time Limit: 1000 mSec

Memory Limit : 32768 KB

http://acm.fzu.edu.cn/problem.php?pid=1147

 Problem Description

In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?

Here is a sample tiling of a 2x17 rectangle.

 Input

Input is a sequence of lines, each line containing an integer number 0 <= n <= 250.

 Output

For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2xn rectangle.

 Sample Input

2
8
12

 Sample Output

3
171
2731

 Source

Albert 2001

在HDU上做过原题,只不过题目数据范围没有这么大,开始一看,激动坏了,递推数列一打,样例水过,直接交WA,然后试试数据发现连long long 都会爆,那就是大数加法了,可是按理大数用二维数组存一下也没什么问题,运行都是完全正确,提交WA了6次,各种方法都试了,WA;

最开始用大数做的时候问队友0的情况,按理输入0输出也是0,杭电上都是数组清0,然后从三开始打表a[i]=a[i-1]+2*a[i-2];这样0就是0,后来才知道0的情况是1,我那个没脾气了,,,你这题这么坑你爸妈知道吗,啊!!我WA了6遍,5个小时没A出这个题,我当时很肯定地对队友说表肯定没错,运行完全正确,可是不造为什么就是WA,还以为大数这里搞错了,,也质疑过0的情况有坑,但我还是没改,因为我本质也是觉得0就是输出0,结果。。。。。。。。。。

建议先去HDU上把这个题A了点击-原题,没什么技巧,博主比较笨,当时做的时候多列了几个样例就发现了规律,这里不过是用大数罢了,但注意特判0,代码拿去:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=251;
int a[N][N];
int main()
{
int n,i,j;
memset(a,0,sizeof(a));
a[1][0]=1,a[2][0]=3;
int c=0;
for(i=3;i<=N;i++)
{
c=0;
for(j=0;j<=N;j++)
{
a[i][j]=a[i-1][j]+2*a[i-2][j]+c;
c=a[i][j]/100;
a[i][j]%=100;
}
}
while(~scanf("%d",&n))
{
if(n==0)
printf("1\n");
else
{
for(j=250;j>=0;j--)
if(a[n][j])
break;
printf("%d",a[n][j]);
for(i=j-1;i>=0;i--)
printf("%02d",a[n][i]);
printf("\n");
}
}
return 0;
}

代码二(AC):

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=260;
int a[N][100];
int main()
{
int n,i,j;
memset(a,0,sizeof(a));
a[1][0]=1;
a[2][0]=3;
int c=0;
for(i=3;i<=N;i++)
{
c=0;
for(j=0;j<=100;j++)
{
a[i][j]=a[i-1][j]+2*a[i-2][j]+c;
c=a[i][j]/10;
a[i][j]%=10;
}
}
while(~scanf("%d",&n))
{
if(n==0)
printf("1\n");
else
{
for(i=99;i>=0;i--)
if(a[n][i])
break;
for(j=i;j>=0;j--)
printf("%d",a[n][j]);
printf("\n");
}
}
return 0;
}

还试过输出%04d的,在进位的时候除以10000和对10000取余就好了,只要特判0,用祥琨大神的话来说怎么写怎么过;

原谅我对这题说了这么多废话,博主此刻心无法平静,是我太年轻了, 没有阅历,没有胆识,更没有能力。。。

FZU- Problem 1147 Tiling,递推坑题,大数水过~~的更多相关文章

  1. UVA10862 - Connect the Cable Wires(递推 + java的大数)

    UVA10862 - Connect the Cable Wires(递推 + java的大数) 题目链接 题目大意:给你n座房子位于一条直线上,然后仅仅给你一个cable service.要求每座房 ...

  2. hdu 1465:不容易系列之一(递推入门题)

    不容易系列之一 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  3. POJ 2441 Arrange the Bulls 状态压缩递推简单题 (状态压缩DP)

    推荐网址,下面是别人的解题报告: http://www.cnblogs.com/chasetheexcellence/archive/2012/04/16/poj2441.html 里面有状态压缩论文 ...

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

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

  5. 计蒜客 28319.Interesting Integers-类似斐波那契数列-递推思维题 (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 I)

    I. Interesting Integers 传送门 应该是叫思维题吧,反正敲一下脑壳才知道自己哪里写错了.要敢于暴力. 这个题的题意就是给你一个数,让你逆推出递推的最开始的两个数(假设一开始的两个 ...

  6. poj 2506 Tiling 递推

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

  7. <每日一题> Day5:简单递推两题

    原题链接 参考代码: #include <iostream> using namespace std; typedef long long ll; + ; ll dp[maxn]; int ...

  8. HOJ 2148&POJ 2680(DP递推,加大数运算)

    Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...

  9. FZU 2129 子序列个数 (递推dp)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2129 dp[i]表示前i个数的子序列个数 当a[i]在i以前出现过,dp[i] = dp[i - 1]*2 - ...

随机推荐

  1. 转 ORACLE数据库ORA-00392 log 4 of thread 1 is being cleared, operation not allowed错误

    现象: 数据库在做to-time recovery, 时候,restore and recover 都是正常的,但是最后一步open resetlogs 报错如下 ORA-00392 原因: 因为是在 ...

  2. c语言读取一个文件夹下的全部文件(jpg / png 文件)

    #include <cstdio> #include <cstring> #include <unistd.h> #include<dirent.h> ...

  3. POJ 3522 Slim Span 暴力枚举 + 并查集

    http://poj.org/problem?id=3522 一开始做这个题的时候,以为复杂度最多是O(m)左右,然后一直不会.最后居然用了一个近似O(m^2)的62ms过了. 一开始想到排序,然后扫 ...

  4. spring boot 的redis 之初理解

    项目到末尾了快, 这几天安排我结合业务场景给项目加上redis 缓存, 我接到这个任务也是懵逼了一会儿: 问了一句让我自己先想办法,没办法硬着头皮查吧, 要不不得不说spring boot 还是好用, ...

  5. let块级引起的闭包思考

    因为es6在node中用的比较频繁,最近在按计划根据阮一峰的es6教程从头开始学习一遍, 第一步遇到的就是“看似非常熟悉”的let小伙伴,核心character如下: 即:let变量的作用域只在块内. ...

  6. JMeter进入接口压力测试

    关键字: Jmeter.单接口.压力测试.插件监听.服务器端 摘要: 使用Jmeter对单个接口进行压力测试:监听并发量对接口响应时间.服务器资源占量.Jmeter本身只能获取到Tomcat的状态,所 ...

  7. 在git远程仓创建项目之后,提交本地项目的使用方法

    命令介绍 git 用户配置 git config --global user.name "张三" git config --global user.email "zhag ...

  8. JQuery日期选择器插件date-input

    JQuery日期选择器插件之date-input 官方网站:http://jonathanleighton.com/projects/date-input/ 下载地址: http://github.c ...

  9. phpstorm 格式化代码

    MAC 安装phpcs.phpcbf composer global require 'squizlabs/php_codesniffer=*' Changed current directory t ...

  10. help命令

    help——获得Shell内置命令的帮助信息 命令所在路径:Shell内置命令 示例1: # help cd 使用which或者whereis查找不到路径的命令一般是Shell内置命令,cd就是一个S ...