HDU-2160 Sow Story

Description

It is said that the price of pork is so expensive, and the famous ACBoy 0068 has also begun to raise pigs. It is strange to say that the pigs he raises can have a piglet at noon every day from the second day of birth, and all of them are born sows.
But the piglets were n’t enough, 0068 adopted a very strange way to manage his pig farm:
for each newborn piglet, he was killed immediately after giving birth to the second piglet and sold it to the supermarket in.
Suppose that on the first day of starting a business, 0068 bought a newborn pig. How many pigs still exist in the pig farm of 0068 on the evening of the Nth day?

Input

The first line of test data contains a positive integer T, representing the number of test data. Next, there are T groups of tests, each group of test data occupies one row, and there is a positive integer N representing the Nth day of 0068 entrepreneurship. (0 <N <20)

Output

For each set of data, please output the number of pigs in the pig farm on the Nth night in one row.

Sample Input

2
2
3

Sample Output

2
3
#include <cstdio>
using namespace std;

int main()
{
    int n, m;
    int a[25] = {0};
    a[1] = 1;
    a[2] = 2;

    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &m);
        for (int j = 3; j <= m; j++)
            a[j] = a[j-2]+a[j-1];
        printf("%d\n", a[m]);
    }
    return 0;
}

 

Published 339 original articles · praised 351 · 170,000 views

Guess you like

Origin blog.csdn.net/Aibiabcheng/article/details/105353361