组合数学(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
除去找规律的那一部分,这道题是一道好题。
#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的更多相关文章
- 组合数学之Pólya计数理论
1 群 群$(G, cdot)$: 闭合, 结合律, 幺元, 逆 1.1 置换群 置换为双射$pi:[n]to [n]$, 置换之间的操作符 $cdot$ 定义为函数的复合, 即$(pi cdot s ...
- 《Mathematical Olympiad——组合数学》——抽屉原理
抽屉原理可以说是组合数学中最简单易懂的一个原理了,其最简单最原始的一个表达形式:对于n本书放到n-1个抽屉中,保证每个抽屉都要有书,则必存在一个抽屉中有2本书.但是这个简单的原理在很多问题中都能够巧妙 ...
- 10601 - Cubes(Ploya)
UVA 10601 - Cubes 题目链接 题意:给定正方体12条棱的颜色,要求用这些棱能组成多少不同的正方体 思路:利用ploya定理去求解,分类讨论,正方体一共24种旋转.相应的旋转方式有4种: ...
- STM32F4_TIM基本延时(计数原理)
Ⅰ.概述 STM32的TIM定时器分为三类:基本定时器.通用定时器和高级定时器.从分类来看就知道STM32的定时器功能是非常强大的,但是,功能强大了,软件配置定时器就相对复杂多了.很多初学者甚至工作了 ...
- Luogu 1351 NOIP 2014 联合权值(贪心,计数原理)
Luogu 1351 NOIP 2014 联合权值(贪心,计数原理) Description 无向连通图 G 有 n 个点,n-1 条边.点从 1 到 n 依次编号,编号为 i 的点的权值为 Wi, ...
- 【等价的穿越】Burnside引理&Pólya计数法
Problem 起源: SGU 294 He's Circle 遗憾的是,被吃了. Poj有道类似的: Mission 一个长度为n(1≤n≤24)的环由0,1,2组成,求有多少本质不同的环. 实际上 ...
- 数学计数原理(Pólya,高精度):SGU 294 He's Circles
He's Circles He wrote n letters "X" and "E" in a circle. He thought that there ...
- 数学计数原理(Pólya):POJ 1286 Necklace of Beads
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7763 Accepted: 3247 ...
- Pólya计数定理
我日啊..被cls的计数题虐得欲仙欲死...根本不会计数QAQ... 不懂数学啊... 前置技能 群 群是二元组\((G,*)\),满足 \(*:(G,G)\rightarrow G\) \(\exi ...
随机推荐
- Ant学习笔记(2) 在Eclipse中使用Ant
Eclipse默认提供了对Ant的支持,在Eclipse中不需要安装任何插件就能直接编辑和运行Ant.Eclipse中包含了一个Ant脚本编辑器,Ant脚本编辑器提供了对Ant脚本的语法搞来高亮.自动 ...
- rabbitMQ实战(一)---------使用pika库实现hello world
rabbitMQ实战(一)---------使用pika库实现hello world 2016-05-18 23:29 本站整理 浏览(267) pika是RabbitMQ团队编写的官方Pyt ...
- Difference Between XML and XAML.
XML, or Extensible Markup Language, is a subset of the more complex SGML (Standard Generalized Mark ...
- How to customize authentication to my own set of tables in asp.net web api 2?
ssuming your table is called AppUser, convert your own AppUser domain object to IUser(using Microsof ...
- .NET中的三种Timer的区别和用法(转)
最近正好做一个WEB中定期执行的程序,而.NET中有3个不同的定时器.所以正好研究研究.这3个定时器分别是: //1.实现按用户定义的时间间隔引发事件的计时器.此计时器最宜用于 Windows 窗 ...
- 在WinForm应用程序中,使用选项卡控件来加载不同的Form界面!
TabPage tp=new TabPage(); your选项卡控件.Controls.Add(tp); From1 frm=new Form1(); frm.TopLevel = false; f ...
- ajax跨域传值
<script type="text/javascript"> function xmlpage(){ $.ajax({ url:'http://localhost/3 ...
- Spring MVC中注解 @ModelAttribute
1.@ModelAttribute放在方法之上,在当前Control内的所有方法映射多个URL的请求,都会执行该方法 @ModelAttribute public void itemsCommon(H ...
- Template 模式
Template 模式是很简单模式,但是也应用很广的模式.Template 是采用继承的方式实现算法的异构,其关键点就是将通用算法封装在抽象基类中,并将不同的算法细节放到子类中实现.Template ...
- 记一个问题的AC
今天突然做一道LCT的染色问题的时候突然想到一个两个月前一道没有AC的题目. 链接 大意是,给一个长度为10^4的序列,最多有255个不同的数字,有最多10^5次方个询问,对于每个询问 l,r 输出[ ...