POJ - 2506 Tiling (递推+高精度运算)@
2017-04-15 10:46
387 查看
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
Sample Output
a
=2*a[n-2]+a[n-1];
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 100 200
Sample Output
3 171 2731 845100400152152934331135470251 1071292029505993517027974728227441735014801995855195223534251
a
=2*a[n-2]+a[n-1];
#include <algorithm> #include <string.h> #include <iostream> #include <stdio.h> #include <string> #include <vector> #include <queue> #include <map> #include <set> using namespace std; typedef long long LL; const int N = 2010; int a[300][300]; int main() { memset(a,0,sizeof(a)); a[0][0]=1, a[1][0]=1,a[2][0]=3; int n; while(scanf("%d", &n)!=EOF) { if(n==2) cout<<3<<endl; else { int digit=1; for(int i=3; i<=n; i++) { int sum=0; for(int j=0; j<digit; j++) { a[i][j]=(sum+a[i-1][j]+2*a[i-2][j])%10000; sum=(sum+a[i-1][j]+2*a[i-2][j])/10000; } if(sum!=0) { a[i][digit++]=sum; } } cout<<a [digit-1]; for(int i=digit-2; i>=0; i--) printf("%04d",a [i]); cout<<endl; } } return 0; }
相关文章推荐
- POJ2506——Tiling(高精度+递推)
- 【POJ】2506 - Tiling(递推,高精度)
- POJ 2506 Tiling(高精度+递推)
- POJ 2506 Tiling (递推+高精度)
- Poj 2506 Tiling (Java高精度 + 递推)
- poj 2506 Tiling(数学:递推+高精度)
- POJ 2506 Tiling 高精度
- poj 2506 Tiling【大数+递推】
- poj 2506 Tiling(递推 大数)
- poj 2506 Tiling(大数+递推)
- POJ 2506 Tiling(DP+大数运算)
- POJ2506 高精度+递推
- POJ 2506 Tiling 高精度
- poj 2506 Tiling 《大数加法+递推》
- poj - 2506 Tiling--递推
- Tiling(POJ 2506 高精度)
- POJ 2506 Tiling (递推 + 大数加法模拟 )
- poj 2506 Tiling 递推
- poj 2506 Tiling 高精度
- POJ 2506 高精度+递推