日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Tri Tiling

發布時間:2023/12/16 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tri Tiling 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一次寫博客。

Problem Description:

In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a 3x12 rectangle.

Input:

Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer 0 ≤ n ≤ 30.

Output:

For each test case, output one integer number giving the number of possible tilings. Sample Input: 2
8
12
-1
Sample Output: 3
153
2131
題目意思給你一個3*n矩形,用2*1的矩形將它填滿,有多少種情況。 這是一題遞推題,首先當n為奇數的時候,3*奇數=奇數,用2*1的矩形是怎樣都填不下去的。 所以只要考慮n為偶數的情況。 設3*n時情況有a[n]種; 當n=2時,有以下三種情況: 當n>2時,如果圖形中不包含n=2時的三種情況的話,那么就只會有2種情況。 例如n=4: 將其反過來又是一種。 根據以上兩種情況可以將長為n的矩形分兩塊:n-2+2;n-4+4;n-6+6……n-n+n; ①n-2+2的情況有a[n-2]*3; ②n-4+4的情況有a[n-4]*2;為什么這里是*2而不是*a[4]?因為4分成2與2的話會與②中的重復,所以只需考慮4中不能分成2與2情況 …… 所以a[n]=a[n-2]*3+2*(a[n-4]+a[n-6]+……+a[n-(n-2)]+a[0](注意a[0]=1)); #include<stdio.h> int a[35]={1,0,3}; int f(int x) {int sum=0;for(int i=x;i>=0;i-=2)sum+=a[i]*2;return sum; }int main() {int n;for(int i=4;i<=30;i+=2){a[i]=a[i-2]*3+f(i-4);a[i-1]=0;}while(scanf("%d",&n)!=EOF){if(n==-1)break;printf("%d\n",a[n]);} }

?

轉載于:https://www.cnblogs.com/-yuxia/p/5268675.html

總結

以上是生活随笔為你收集整理的Tri Tiling的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。