Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One day, while working on his latest project, he was intrigued by the number of different ways in which he could order several objects to fill an arbitrary region. Expert as he was in this material, he saw at a glance that this was going to be too hard, for there seemed to be innumerable ways to do this. To make his task a little easier, he decided to start with only two kinds of objects: squares with width 1 and height 1, and rectangles with width 2 and height 1. After working on it for half an hour, he knew that even this was too much, for all of his paper was filled with pages like this. The only paper left was his toilet paper, and strange as it now seems, he continued with his task. Fortunately the width of the toilet paper equaled the width of the rectangle, which simplified things a lot. This seemed to do just fine, for in a few minutes time, he produced the following drawing:
Mondriaan decided to make several of these drawings, each on a piece of toilet paper with a different length. He wanted to give the drawings in his ‘toilet series’ names according to the last digit of the number of ways to fill a piece of toilet paper of a particular length with squares and rectangles. Computers might come in handy in cases like this, so your task is to calculate the name of the drawing, given the length of the toilet paper. The length will be measured in the same dimension as the squares and rectangles.
Input
The input consists of a line containing the number N (1≤N≤100) of drawings in the series. Each consecutive line consists of a number L (0≤L≤1000000) which is the length of the piece of toilet paper used for the drawing.
Output
The output consists of the number that is the name for the corresponding drawing.
Sample Input
5 0 1 2 3 4
Sample Output
1 2 7 2 1
题目分析:
直接递归公示f(n)=2*f(n-1)+3*f(n-2)+2*f(n-3)+……+2*f(0)
/*
*/
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<cmath>
#include<iomanip>
#include<list>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <stack>
#include<queue>
#include<string.h>
#include<set>
using namespace std;
int result[1000001];
int main()
{
result[0]=1;
result[1]=2;
int sum=3;
for(int i=2;i<1000001;i++)
{
result[i]=(result[i-2]+sum*2)%10;
sum=(result[i]+sum)%10;
}
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int tmp;
cin>>tmp;
cout<<result[tmp]<<endl;
}
}