组合数学(Pólya计数原理):UvaOJ 10601 Cubes

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=15;
 6 int a[maxn][maxn]={
 7     {12,1,1,1,1,1,1,1,1,1,1,1,1},
 8     {3,4,4,4},{6,2,2,2,2,2,2},
 9     {7,1,1,2,2,2,2,2},{4,3,3,3,3},
10 };
11 int b[maxn]={1,6,3,6,8};
12 int c[maxn];
13 
14 int DFS(int p,int id){
15     if(p>a[id][0])
16         return 1;
17     int ret=0;
18     for(int i=1;i<=6;i++)//every color
19         if(c[i]>=a[id][p]){
20             c[i]-=a[id][p];
21             ret+=DFS(p+1,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,0,sizeof(c));
32         for(int i=1,x;i<=12;i++){
33             scanf("%d",&x);c[x]+=1;
34         }
35         ans=0;
36         //every kind of permutation
37         for(int i=0;i<=5;i++)
38             ans+=DFS(1,i)*b[i]; 
39         //b[i]: the number of the iTH permutation
40         printf("%d\n",ans/24);
41     }
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/TenderRun/p/5656204.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值