Hangzhou Electric---2068 RPG's Wrong row

Source: Internet
Author: User

Problem Description this summer holiday training team The first composition girls team, including a team called RPG, but as one of the training team members of the wild camel unexpectedly do not know RPG three person specifically who. RPG gave him the chance to let him guess, the first guess: R is the princess, p is the grass, G is the Moon hare; the second guess: R is grass, p is the Moon hare, G is the princess; Third guess: R is grass, p is princess, G is moon Hare; The poor wild camel finally divided the RPG for the sixth time. Because of the drive of the RPG, more and more women to do ACM, our wild camel want to know them, but now there are n many people, he has to guess the number of times, in order not to embarrass the wild camel, girls only ask him to correct half or above even if the clearance, how many groups of answers can make him smooth clearance.

Input

There are multiple case entries in the input data, each case containing an n, representing a few girls, (n<=25), n = 0 input end.

Output

Given how many sets of answers will make him successful.

Sample Input

1

2

0

Sample Output

1

1

Author

Rabbit

Source RPG

Practice Competition

Recommend

Lcy

Analysis: This is a wrong combination of problems, at first I have a wrong idea: think right and wrong must be N/2, in fact, should be wrong in 0---N/2 can. A wrong-row formula is required, F (1) =0;f (2) = 1;

f (i) = (i-1) * (f (i-1) +f (i-2)); Since the number is very large with __int64, the code is as follows:

#include <iostream> #include <stdio.h>using namespace std;__int64 c (int n,int m) {    __int64 up=1;    __int64 down=1;    for (int i=n;i>n-m;i--)                                  //simple permutation combination, details    {        up=up*i;    }    for (int j=1;j<=m;j++)    {        down=down*j;    }    return up/down;} int main () {    __int64 a[30];    int n;    A[1]=0;a[2]=1;    for (int i=3;i<30;i++)                                       //Wrong-row formula        a[i]= (i-1) * (A[i-1]+a[i-2]);    while (Cin>>n)    {        if (n==0) break            ;        __int64 Sum=1;        for (int i=1;i<=n/2;i++)        {            sum=sum+a[i]*c (n,i);        }        printf ("%i64d\n", sum);    }    return 0;}


Hangzhou Electric---2068 RPG's Wrong row

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.