首页 > 编程知识 正文

【Codeforces 1433 E】Two Round Dances,排列组合,公式

时间:2023-05-03 16:44:59 阅读:65934 作者:2532

problem E. Two Round Dances

时间限制per test1 second

内存极限测试256兆字节

输入标准输入

输出标准输出

One day,npeople(nisanEvennumber ) metonaplazaandmadetworounddances, eachrounddanceconsistsofexactlyn2people.yourtaskistofindthenumberofwaysnpeoplecanmaketworoundddancesifeachroundanceconsist sople

rounddanceisadancecircleconsistingof1ormorepeople.tworounddancesareindistinguishable (equal )。 ifonecanbetransformedtoanotherbychoosingthefirstparticipant.for example,round dances [ 1,3,4,2 ],[ 4,2,1,3 ] and

For example,IFN=2thenthenumberofwaysis 1: onerounddanceconsistsofthefirstpersonandthesecondoneofthesecondperson。

For example,IFN=4thenthenumberofwaysis3. possible options 3360

onerounddance—[ 1,2 ],another—[ 3,4 ];

onerounddance—[ 2,4 ],another—[ 3,1 ];

onerounddance—[ 4,1 ],another—[ 3,2 ]。

yourtaskistofindthenumberofwaysnpeoplecanmaketworounddancesifeachrounddanceconsistsofexactlyn2people。

输入输出

theinputcontainsoneintegern (2n20 ),n is an even number。

输出

printoneinteger-thenumberofwaystomaketworounddances.itisguaranteedthattheanswerfitsinthe 64-bitintegerdatatype。

Examples

输入复制

2

输出复制

1

输入复制

4

输出复制

3

输入复制

8

输出复制

1260

输入复制

20

输出复制

12164510040883200

解决方案/*题意:给出长度为n的序列(1.n ),等分为两个环。 被要求有几种区分方法。 思路:先选n/2人进入第一组,方法数为c(n/2,n )。 然后设定组内排名。 因为是戒指,所以有(n/2-1 )! 因为有两组种子,所以要挂两次。 最后,(x,y )和(y,x )是等价的,所以答案除以2。 答案可以在经合组织找到。 //# include bits/stdc.husingnamespacestd; 泰普德夫龙龙LL; 常数上限=110; LL f[maxn]; int main () IOs :3360 sync _ with _ stdio (false ); int n; cin n; f[0]=1; for(intI=1; i=n; I ) f(I )=f(I-1 ) *I; LL ans=f[n]/f[n/2]/f[n/2]; ans *=f[n/2-1]; ans *=f[n/2-1]; ans /=2; coutans'n '; 返回0; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。