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

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

 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
int a[maxn][maxn]={
{,,,,,,,,,,,,},
{,,,},{,,,,,,},
{,,,,,,,},{,,,,},
};
int b[maxn]={,,,,};
int c[maxn]; int DFS(int p,int id){
if(p>a[id][])
return ;
int ret=;
for(int i=;i<=;i++)//every color
if(c[i]>=a[id][p]){
c[i]-=a[id][p];
ret+=DFS(p+,id);
c[i]+=a[id][p];
}
return ret;
} int main(){
int T,ans;
scanf("%d",&T);
while(T--){
memset(c,,sizeof(c));
for(int i=,x;i<=;i++){
scanf("%d",&x);c[x]+=;
}
ans=;
//every kind of permutation
for(int i=;i<=;i++)
ans+=DFS(,i)*b[i];
//b[i]: the number of the iTH permutation
printf("%d\n",ans/);
}
return ;
}

组合数学(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. Java 8 被动迭代式特性介绍(转自IBM)

    编程语言一般都需要提供一种机制用来遍历软件对象的集合,现代的编程语言支持更为复杂的数据结构,如列表.集合.映射和数组.遍历能力是通过公共方法提供,而内部细节都隐藏在类的私有部分,所以程序员不需要了解其 ...

  2. 10.24 noip模拟试题

    尼玛pdf依旧不会粘23333 /* 每段合并到总的里面 假设总的有X个 这一段有Y个 一共有X+1个空 那么就有 C(X+1,1)+C(X+1,2)+C(X+1,3)+...+C(X+1,Y) 这样 ...

  3. transition的四个属性

    transition-property 规定设置过渡效果的 CSS 属性的名称. transition-duration 规定完成过渡效果需要多少秒或毫秒. transition-timing-fun ...

  4. Android使用 selector 自定义控件背景 (以spinner 为例)

    1. 在drawable中设置背景spinner_style.xml 文件  如图: 2. 在 styles.xml 中添加该背景 3. 最后在 spinner 控件添加样式 4.参考 http:// ...

  5. php_curl扩展在WINDOWS2003上如何添加

    一.使用星外PHP安装后 二.修改环境变量,PATH: c:\php;c:\php\ext;%SystemRoot%\system32;

  6. ZendStudio快捷键

    Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当前 ...

  7. (JAVA)从零开始之--对象输入输出流ObjectInputStream、ObjectOutputStream(对象序列化与反序列化)

    对象的输入输出流 : 主要的作用是用于写入对象信息与读取对象信息. 对象信息一旦写到文件上那么对象的信息就可以做到持久化了 对象的输出流: ObjectOutputStream 对象的输入流:  Ob ...

  8. LA 6856 Circle of digits 解题报告

    题目链接 先用后缀数组给串排好序.dc3 O(n) 二分答案+贪心check 答案的长度len=(n+k-1)/k 如果起点为i长为len串大于当前枚举的答案,i的长度取len-1 从起点判断k个串的 ...

  9. Eclipse中修改Maven Repository

    1. 下载最新的Maven,解压到目录下 Maven下载地址: http://maven.apache.org/download.cgi 2. 修改config/settings.xml文件,在loc ...

  10. 讯飞语音SDK Android平台使用

    1. 支持功能介绍: 2. Android API主要业务接口和流程介绍 -------------------------------------------------------- 工程代码: ...