poj 2506Tiling

<div class="ptt" lang="en-US" style="text-align: center; font-size: 18pt; font-weight: bold; color: blue;">Tiling</div><div class="plm" style="text-align: center;font-size:14px;"><table align="center"><tbody><tr><td><strong>Time Limit:</strong> 1000MS</td><td width="10px"> </td><td><strong>Memory Limit:</strong> 65536K</td></tr><tr><td><strong>Total Submissions:</strong> 9204</td><td width="10px"> </td><td><strong>Accepted:</strong> 4378</td></tr></tbody></table></div><p class="pst" style="font-size: 18pt; font-weight: bold; color: blue;">Description</p><div class="ptx" lang="en-US" style="font-family: "Times New Roman", Times, serif;font-size:14px;">In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? 
Here is a sample tiling of a 2x17 rectangle. 
<center><img src="http://poj.org/images/2506_1.jpg" alt="" /></center>
</div><p class="pst" style="font-size: 18pt; font-weight: bold; color: blue;">Input</p><div class="ptx" lang="en-US" style="font-family: "Times New Roman", Times, serif;font-size:14px;">Input is a sequence of lines, each line containing an integer number 0 <= n <= 250.</div><p class="pst" style="font-size: 18pt; font-weight: bold; color: blue;">Output</p><div class="ptx" lang="en-US" style="font-family: "Times New Roman", Times, serif;font-size:14px;">For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2xn rectangle. 
</div><p class="pst" style="font-size: 18pt; font-weight: bold; color: blue;">Sample Input</p><pre class="sio" style="font-family: "Courier New", Courier, monospace;font-size:14px;">2
8
12
100
200

Sample Output

3
171
2731
845100400152152934331135470251
1071292029505993517027974728227441735014801995855195223534251

//递推公式类似与oj 上的骨牌问题
 

#include<iostream>
#include<stdio.h>
using namespace std;
int str[251][101];//用数组储存  一行一行的存
int main()
{
   int i,j,t;
   str[0][0]=1;//0的时候
   str[1][0]=1;//长度为一的时候
   str[2][0]=3;//长度为三的时候
   t=0;//临时变量
   for(  i = 3; i<=250 ;i++ )//一共250行   储存250种
   {
       for(j=0; j<=100 ; j++)//用数组储存
       {
           t += str[i-1][j] + 2*str[i-2][j];//递推公式   (这里储存的顺序是从个位开始的,方便相加)  (包括了进位)
           str[i][j] = t%10;//储存当前位数的数,如果大于10  取余 进位
           t=t/10;//看看是否需要进位
       }

   }
   int n;
   while(~scanf("%d",&n))
   {
       for(i=100;i>=0;i--)
       {
             if(str[n][i]!=0)
                  break;
       }
       for(;i>=0;i--)
        printf("%d",str[n][i]);
       printf("\n");
   }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值