topcoder Single Round Match 457 Round 1 - Division I, Level Two baTheHexagonsDivOne
来源:互联网 发布:中国乘用车8月销量数据 编辑:程序博客网 时间:2024/05/23 17:14
把1到2*n填入下图中:
使得相邻的两个数模n不同余,考虑旋转,有多少种填法。
1到2*n中模n有n种答案,每种两个。中间的有2*n中填法,后面的只能选择剩下的模n为另外n-1个结果的数字。只有4种情况
1+1+1+1+1+1
1+1+1+1+2
1+1+2+2
2+2+2
考虑旋转的排列时只要固定一个数的位置,再去考虑其他数字就可以了。
第一种情况先在模n的n-1个答案中选6个,然后每种的2个中选1个,固定一个,剩下5!种排法:
C(n-1,6)*2^6*5!
第二种情况先在模n的n-1个答案中选5个,5个中选一个作为出现2次的,然后剩下的每种的2个中选1个。再考虑排列,把出线两次的中的一个固定在1号位置,考虑另一个能放得位置就可以了。
C(n-1,5)*C(5,1)*2^4*(3*4!)
剩下的以此类推即可。关键是注意到环排列就是固定一个数的位置,再去考虑剩下位置的排列。固定的尽量选特殊的数字,即出现两次的数字就能简化计算。只有6个数,纸上推一下就可以了。
#include <bits/stdc++.h>#define maxn 200using namespace std;long long C[maxn][maxn];class TheHexagonsDivOne{public: long long count(int n){for(int i=0;i<maxn;i++){C[i][0]=C[i][i]=1;for(int j=1;j<i;j++)C[i][j]=C[i-1][j]+C[i-1][j-1];}long long ans=2*n;ans=ans*(7680*C[n-1][6]+1152*5*C[n-1][5]+192*6*C[n-1][4]+32*C[n-1][3]);return ans;}};
0 0
- topcoder Single Round Match 457 Round 1 - Division I, Level Two baTheHexagonsDivOne
- Topcoder Single Round Match 453.5 Round 1 - Division I, Level Two TheProduct
- Member Single Round Match 461 Round 1 - Division I, Level Two BuildingCities
- Single Round Match 464 Round 1 - Division I, Level Two ColorfulDecoration
- Member Single Round Match 465 Round 1 - Division I, Level Two GreenWarfareze
- Member Single Round Match 474 Round 1 - Division I, Level Two TreesCount
- Single Round Match 477 Round 1 - Division I, Level Two PythTriplets
- Single Round Match 480 Round 1 - Division I, Level Two NetworkSecurity
- Single Round Match 479 Round 1 - Division I, Level Two TheAirTripDivOne
- Single Round Match 506 Round 1 - Division I, Level Two SlimeXGrandSlimeAuto
- Single Round Match 524 Round 1 - Division I, Level Two LongestSequence
- Single Round Match 573 Round 1 - Division I, Level Two SkiResorts
- Single Round Match 508 Round 1 - Division I, Level Two YetAnotherORProblem
- Single Round Match 517 Round 1 - Division I, Level Two AdjacentSwaps
- Single Round Match 462 Round 1 - Division I, Level Three WarTransportation
- Single Round Match 459 Round 1 - Division II, Level Three gaiParkAmusement
- Single Round Match 671 Round 1 - Division II, Level Three(状压DP)(略难)
- 2010 TCO Algorithm Online Round 5 - Division I, Level Two LongJourney
- Verilog 学习笔记之数据类型
- kO9f RqdXzlouis vuitton outlet obxx 9OE
- kqfs 0FAeKcheap burberry s7P9 Ops
- io流的小事例
- CGAffineTransformMakeTranslation的使用问题
- topcoder Single Round Match 457 Round 1 - Division I, Level Two baTheHexagonsDivOne
- Google-APAC2015-"Password Attacker"
- Android AsynTask 异步线程处理讲解与代码测试
- SPPS java 创建template
- 去哪兒網服務電話號碼是多少-百度百科
- 面经
- 去哪兒網官方電話號碼是什麽-百度百科
- boost环境搭建
- 高效SQL语句必杀技