[Lcez school third test T1] [explanations] folder

// This is actually the number of Cattleya

AJH building blocks

【Problem Description】

Since AJH too much food, so he used to spend time only way building blocks.
AJH came after the death of Ben God of heaven, we all know, only God can enter God Ben Ben heaven, but only the konjac Amorphophallus
konjac hell, so he needs to pass the test in order to enter God Ben heaven. At this time, the administrator Ben God of heaven _rqy brought
a box, there was a note above: in this case there are an infinite number of different sizes but all is a positive integer side lengths of a rectangular plot
of wood, each of which are the building blocks there are an infinite number, now, you have to choose the 1s in the n building blocks, a shelter of a stepped n-layer.
This problem, of course not beat clever AJH, he eventually get into the paradise of God Ben, Ben became a god.
Now Ben AJH God to give you a test, he said: "Please answer this question, how many different kinds of take the law allows me to be God ran
it a lot because it may take the law, so please tell me it is divided by 19,260,817 of? it! "

[Input Format]

A number n

[Output format]

A line output integer representing take several different methods. Since AJH saw large numbers on the sick, so you lose
a number of take the law remainder of the division of 19,260,817.

[Sample input]

3

[Sample output]

5

Sample [explain]

There are five kinds as shown in FIG take the law:

[Agreed] with the scale data

To 100% of the data, 0 <n≤20

solution

For example to solve
for n = 4
there are several situations

that is filling in a block of purple, purple filler blocks are then divided in two parts, multiplied by the number of programs.
This solution over
the code this way:

for(int i=4;i<=n;i++)
{
    for(int j=1;j<=i;j++)//紫块的宽度
    {
        f[i]+=f[j-1]*f[i-j];f[i]%=MOD;
    }
}

How do I seek death of

// start should not give a f [4] initial value
// there is multiplication, * 19,260,817 19,260,817 Long to open Long
// In order to save time (in fact, this time is not entirely the province, the province also wrong), for i sub parity,
but then do not quite understand, to the sub wrong. In fact, is not judged by 2 special odd, but then I became engaged in an even number
and so go wrong due to misinterpreted as an even number, line 29 at the time j have not taken = i / 2

code

#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MOD 19260817
//一开始不应该给f[4]赋初值
//有乘法,19260817*19260817要开long long
//为了省时间(其实这个时间是完全不用省的,省了还错),对i分了奇偶,
//但当时搞的不是太明白, 给分错了。其实是奇数时特判不用乘2,但我当时搞成了偶数 
//并且这样错下去,由于错误地理解为偶数,第29行当时j就没取=i/2 

using namespace std;
long long f[30], n;//
int main()
{
//  freopen("block.in","r",stdin);
//  freopen("block.out","w",stdout);
    cin >> n;
    f[0]=1;
    f[1]=1;
    f[2]=2;
    f[3]=5;
//  f[4]=14;
    for(int i=4;i<=n;i++){
        if(i%2==1){// 
            for(int j=1;j<=i/2;j++){
                f[i]+=f[i-j]*f[j-1]*2;
                f[i]%=MOD;
            }
            f[i]+=f[i/2]*f[i/2];
            f[i]%=MOD;
        }
        else{
            for(int j=1;j<=i/2;j++){
                f[i]+=f[i-j]*f[j-1]*2;
                f[i]%=MOD;
            }
        }
    }
    cout  << f[n] << endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/ZhengkunJia/p/12481856.html