RPG's Wrong row

Source: Internet
Author: User

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 8387 Accepted Submission (s): 3415


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 data has multiple case, each case includes an n, representing a few girls, (n<=25), n = 0 input end.

Sample Input120

Sample OUTPUT1

authorrabbit   thought: Find n the number of the wrong row of the law took a long time, the law as follows 1  1*1=12  1*1=13  1*2=24  3*3=95 4*11=446 5*53= 265   so the number of rows of n is: (N-1 of the number of wrong rows +n-2) * (n-1)   Guess half success, for example:n=6  1. Guess 3, choose 3 from 6, and the rest should meet the wrong row, C (6,3) *rcd[6-3]  2. Guess 4, choose 4, the rest of the wrong row, then there is C (6,4) *rcd[6-4]   guess 5 when that means the sixth also guessed, so 5,6 is 1  
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;long Long rcd[30];int n;void init ()//Initialize count the number of rows per digit (that is, n number each is not in its own correct position on the number of species) {    rcd[2]=1;    rcd[3]=2;    for (int i=4;i<=25;++i)    rcd[i]= (Rcd[i-1]+rcd[i-2]) * (i-1);} int getc (int m,int k) {    int ans=m;    for (int i=2;i<=k;++i)    ans=ans* (m-i+1)/I;    return ans;} void Solve () {    if (n==1) cout<<1<<endl;    else if (n==2) cout<<1<<endl;    else if (n==3) cout<<1<<endl;    else if (n==4) cout<<7<<endl;    else{        Long long ans=0,m;        if (n&1) m= (n>>1) +1;        else m=n>>1;        for (int i=m;i<n-1;++i) {            ans+=getc (n,i) *rcd[n-i];        }       cout<<ans+1<<endl;    }} int main () {    std::ios::sync_with_stdio (false);    Init ();    while (scanf ("%d", &n) &&n)    solve ();

Source RPG session

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.