Tri Tiling

Tri Tiling

Grade: 10 / Discount: 0.8

Time Limit:1000MS Memory Limit:65536K

Description

In how many ways can you tile a 3xn rectangle with 2x1 dominoes?

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

Output
For each test case, output one non negative integer, which is the number of possible tilings.

Sample Input

2

8

12

-1

Sample Output

3

153

2131

Source
Waterloo local 2005.09.24

 

#include<stdio.h>
int memo[40][10];

main() {
    int n;
    int i;
    memo[0][0] = 1;

    for( i = 1; i < 32; i++ ) {
        memo[i][0] = memo[i-1][1] + memo[i-1][4] + memo[i-1][7];
        memo[i][1] = memo[i-1][0] + memo[i-1][6];
        memo[i][2] = memo[i-1][5];
        memo[i][3] = memo[i-1][4];
        memo[i][4] = memo[i-1][0] + memo[i-1][3];
        memo[i][5] = memo[i-1][2];
        memo[i][6] = memo[i-1][1];
        memo[i][7] = memo[i-1][0];
    }
scanf("%d", &n);
    while(n!=-1) 
   {
        printf("%d\n", memo[n][0]);
scanf("%d", &n);
    }
}


 

Tri Tiling(Modified)

Grade: 10 / Discount: 0.8

Time Limit:3000MS Memory Limit:65536K

Description

In how many ways can you tile a 3xn rectangle with 2x1 dominoes? Find the answer taken modulo 9973.

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

Output
For each test case, output one non negative integer, which is the number of possible tilings modulo 9973.

Sample Input

2

8

12

-1

Sample Output

3

153

2131

Source
Waterloo local 2005.09.24 Modified by Liu Qinghui

 

你可能感兴趣的:(Integer,input,each,output)