Cubes

You are given 12 rods of equal length. Each of them is colored in certain color. Your task is to determine in how many different ways one can construct a cube using these rods as edges. Two cubes are considered equal if one of them could be rotated and put next to the other, so that the corresponding edges of the two cubes are equally colored.

Input

The first line of input contains T (1≤T≤60), the number of test cases. Then T test cases follow. Each test case consists of one line containing 12 integers. Each of them denotes the color of the corresponding rod. The colors are numbers between 1 and 6.

Output

The output for one test consists of one integer on a line - the number of ways one can construct a cube with the described properties.

Sample Input

Sample Output

3

1 2 2 2 2 2 2 2 2 2 2 2

1 1 2 2 2 2 2 2 2 2 2 2

1 1 2 2 3 3 4 4 5 5 6 6

1

5

312120

Problem source: Bulgarian National Olympiad in Informatics 2003

Problem submitter: Ivaylo Riskov

Problem solution: Ivaylo Riskov, K M Hasan

  除去找规律的那一部分,这道题是一道好题。

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. using namespace std;
  5. const int maxn=;
  6. int a[maxn][maxn]={
  7. {,,,,,,,,,,,,},
  8. {,,,},{,,,,,,},
  9. {,,,,,,,},{,,,,},
  10. };
  11. int b[maxn]={,,,,};
  12. int c[maxn];
  13.  
  14. int DFS(int p,int id){
  15. if(p>a[id][])
  16. return ;
  17. int ret=;
  18. for(int i=;i<=;i++)//every color
  19. if(c[i]>=a[id][p]){
  20. c[i]-=a[id][p];
  21. ret+=DFS(p+,id);
  22. c[i]+=a[id][p];
  23. }
  24. return ret;
  25. }
  26.  
  27. int main(){
  28. int T,ans;
  29. scanf("%d",&T);
  30. while(T--){
  31. memset(c,,sizeof(c));
  32. for(int i=,x;i<=;i++){
  33. scanf("%d",&x);c[x]+=;
  34. }
  35. ans=;
  36. //every kind of permutation
  37. for(int i=;i<=;i++)
  38. ans+=DFS(,i)*b[i];
  39. //b[i]: the number of the iTH permutation
  40. printf("%d\n",ans/);
  41. }
  42. return ;
  43. }

组合数学(Pólya计数原理):UvaOJ 10601 Cubes的更多相关文章

  1. 组合数学之Pólya计数理论

    1 群 群$(G, cdot)$: 闭合, 结合律, 幺元, 逆 1.1 置换群 置换为双射$pi:[n]to [n]$, 置换之间的操作符 $cdot$ 定义为函数的复合, 即$(pi cdot s ...

  2. 《Mathematical Olympiad——组合数学》——抽屉原理

    抽屉原理可以说是组合数学中最简单易懂的一个原理了,其最简单最原始的一个表达形式:对于n本书放到n-1个抽屉中,保证每个抽屉都要有书,则必存在一个抽屉中有2本书.但是这个简单的原理在很多问题中都能够巧妙 ...

  3. 10601 - Cubes(Ploya)

    UVA 10601 - Cubes 题目链接 题意:给定正方体12条棱的颜色,要求用这些棱能组成多少不同的正方体 思路:利用ploya定理去求解,分类讨论,正方体一共24种旋转.相应的旋转方式有4种: ...

  4. STM32F4_TIM基本延时(计数原理)

    Ⅰ.概述 STM32的TIM定时器分为三类:基本定时器.通用定时器和高级定时器.从分类来看就知道STM32的定时器功能是非常强大的,但是,功能强大了,软件配置定时器就相对复杂多了.很多初学者甚至工作了 ...

  5. Luogu 1351 NOIP 2014 联合权值(贪心,计数原理)

    Luogu 1351 NOIP 2014 联合权值(贪心,计数原理) Description 无向连通图 G 有 n 个点,n-1 条边.点从 1 到 n 依次编号,编号为 i 的点的权值为 Wi, ...

  6. 【等价的穿越】Burnside引理&Pólya计数法

    Problem 起源: SGU 294 He's Circle 遗憾的是,被吃了. Poj有道类似的: Mission 一个长度为n(1≤n≤24)的环由0,1,2组成,求有多少本质不同的环. 实际上 ...

  7. 数学计数原理(Pólya,高精度):SGU 294 He's Circles

      He's Circles He wrote n letters "X" and "E" in a circle. He thought that there ...

  8. 数学计数原理(Pólya):POJ 1286 Necklace of Beads

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7763   Accepted: 3247 ...

  9. Pólya计数定理

    我日啊..被cls的计数题虐得欲仙欲死...根本不会计数QAQ... 不懂数学啊... 前置技能 群 群是二元组\((G,*)\),满足 \(*:(G,G)\rightarrow G\) \(\exi ...

随机推荐

  1. HTML5 WebAudioAPI(三)--绘制频谱图

    HTML <style> #canvas { background: black; } </style> <div class="container" ...

  2. RecyclerView实例-实现可下拉刷新上拉加载更多并可切换线性流和瀑布流模式(1)

    摘要 最近项目有个列表页需要实现线性列表和瀑布流展示的切换,首先我想到的就是上 [RecyclerView],他本身已经很好的提供了三种布局方式,只是简单做个切换应该是很简单的事情,如果要用Recyc ...

  3. oracle中所有关于时间日期的问题总结

    select current_date as 当前会话时间,sysdate as 系统时间, systimestamp as 系统详细时间 from dual;

  4. splice 操作符

    几乎所有的数组操作都可用 splice 实现. 除了第一个参数,数组,为必须,其余的参数都不是必须的. splice ARRAY, OFFSET, LENGTH, LIST OFFSET 和 LENG ...

  5. 使用BeanUtils组件

    使用BeanUtils组件 前提 1:导入commons-beanutils-1.8.3.jar        //根据  本人使用的是1.8.3的版本 2:导入日志包      //就是loggin ...

  6. mysql锁死的现象判断

    一般发生表锁死这种低级问题,就有两种情况:1.程序员水平太菜,2.程序逻辑错误. 一旦发生系统会出现超时,关键是有可能你看不到正在活动的php进程,而系统的慢查询日志也不会记录,只能通过show fu ...

  7. 『重构--改善既有代码的设计』读书笔记----Extract Class

    在面向对象中,对于类这个概念我们应该有一个清晰的责任认识,就是每个类应该只有一个变化点,每个类的变化应该只受到单一的因素,即每个类应该只有一个明确的责任.当然了,说时容易做时难,很多人可能都会和我一样 ...

  8. HTML5画布

  9. Asp.net 实现图片缩放 无水印(方法一)

    /// <summary> /// 图片缩放 无水印 /// </summary> /// <param name="sourceFile">图 ...

  10. Smart Client Software Factory安装

    首先要安装 Visual Studio 2010 SDK 不然无法安装 Smart Client Software Factory 2010 然后按顺序安装 GAX 2010 http://visua ...