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. POJ - 3608 Bridge Across Islands【旋转卡壳】及一些有趣现象

    给两个凸包,求这两个凸包间最短距离 旋转卡壳的基础题 因为是初学旋转卡壳,所以找了别人的代码进行观摩..然而发现很有意思的现象 比如说这个代码(只截取了关键部分) double solve(Point ...

  2. jQuery失去焦点的时候注册验证

    //注册验证$('form :input').blur(function () { if ($("#txtName").val() == "") { $(&qu ...

  3. 通过WebClient/HttpWebRequest实现http的post/get方法

    ///<summary>/// 通过WebClient类Post数据到远程地址,需要Basic认证: /// 调用端自己处理异常 ///</summary>///<par ...

  4. 用sed、awk、grep同时匹配多个条件(与模式、或模式)

    同时匹配ABC 和 123:sed -n '/ABC/{/123/p}' awk '/ABC/&&/123/{ print $0 }' grep -E '(ABC.*123|123.* ...

  5. 解决每次升级Xcode后三方插件失效问题

    其实就是插件里面的UIID没有加新XcodedeUIID 拿常用的Alactraz来说 在Terminal中 un these 2 lines in terminal:1:find ~/Library ...

  6. 一条sql语句循环插入N条不同记录(转)

    SET NOCOUNT ON IF (OBJECT_ID('TB' ) IS NOT NULL ) DROP TABLE TB GO CREATE TABLE TB(ID INT IDENTITY ( ...

  7. SGU 164.Airline(结论题)

    时间限制:0.25s 空间限制:4M 题意: 在n(1<=n<=200)个点的无向完全图中,有m种不同的边.现在从中选择不超过(m+1)/2种边,使得任意两点可以通过不超过3条边互相到达. ...

  8. ios开发相关网站

    1.苹果开发者中心(ios Dev Center):最权威的学习ios开发的地方,提供ios开发所能用到的所有内容(包含文档.指南以及实例代码). https://developer.apple.co ...

  9. 每天一条linux命令——login

    login命令用于给出登录界面,可用于重新登录或者切换用户身份,也可通过它的功能随时更换登入身份.当/etc/nologin文件存在时,系统只root帐号登入系统,其他用户一律不准登入. 语法: lo ...

  10. Why Doesn’t Drag-and-Drop work when my Application is Running Elevated? – A: Mandatory Integrity Control and UIPI(转载)

    f you run notepad elevated (Right click | Run as Administrator), and you try and drag-and-drop a fil ...