Title: give you a 2*n ground, with 1*2 and 2*2 floor tile paved, how many different plans.
Analysis: Combinatorial mathematics, dynamic programming. Direct find to push relationship solver.
Because, it is only possible that the last column is a whole (1 cases) or the last two columns are a whole (two cases);
So, there is a recursive formula: F (n) = f (n-1) + 2*f (n-2);
It can be solved using dynamic programming or a parent function (an = (POW (2,n+1)-pow ( -1,n+1))/3).
Description: Large integer operation, here using DP solution, seemingly fast power will quickly ╮(╯▽╰)╭.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;int ans[255][101],two[101];void copy_array (int *a, int *b) {for (int i = 0; I < 100; + + i) a[i] = B[i];} void Add_array (int *c, int *a, int *b) {for (int i = 0; I < + + i) c[i] = 0;for (int i = 0; I < + + i) {C[i] + = A[i]+b[i];if (C[i] > 9) {c[i+1] + c[i]/10;c[i]%= 10;}} void Output_array (int *a) {int end = 100;while (end &&!a[end])--end;while (end >= 0) printf ("%d", a[end--]);p rintf ("\ n");} int main () {memset (ans, 0, sizeof (ans)); ans[0][0] = 1;ans[1][0] = 1;for (int i = 2; i < 252; + + i) {Add_array (II, Ans[i -2], ans[i-2]); Add_array (Ans[i], ans[i-1], and);} int N;while (~SCANF ("%d", &n)) Output_array (Ans[n]); return 0;}
UVa 10359-tiling