组合数学(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 ...
随机推荐
- NetworkOnMainThreadException
来自:http://www.2cto.com/kf/201402/281526.html NetworkOnMainThreadException extends RuntimeException j ...
- JS调用android逻辑方法
1.安卓打开webview时做如下配置 并做一回调接口 这里注意的是 参数 FULIBANG 和 回调接口方法 jsCallWebView 一会在JS里会用到 ================= ...
- RESTful互联网框架
在我们日常接触的网络中,对于非程序员来说主要关注的就是在网上找到自己需要的资料,但是对于开发者来说,主要关注的就是将结构和页面,以及功能的分离,但是如何划分这个结构呢,或许我们知道的有MVC框架,甚至 ...
- HTML页面中启用360浏览器极速模式
今天做页面突然遇到浏览器一直在兼容模式下运行,体验不好,通过查询文档,在<head>中加入<meta name="renderer" content=" ...
- AngularJS+NodeJS环境搭建
需要安装的软件: node-v0.12.7-x64.msi python-2.7.10.amd64.msi Git-2.5.1-64-bit.exe (注意:Git安装时,需要选择的步骤) 安装位置 ...
- Servlet(三)
重定向 服务器向浏览器发送一个302状态码以及一个Location消息头(该消息头的值是一个地址,称之为重定向地址),浏览器收到后会立即向重定向的地址发出请求,使用相应对象的API方法实现(respo ...
- php计算时间差/两个时间日期相隔的天数,时,分,秒.
function timediff( $begin_time, $end_time ) { if ( $begin_time < $end_time ) { $starttime = $begi ...
- 那些年被我坑过的Python——一夫当关 第十三章(堡垒机初步设计)
堡垒机架构 堡垒机的主要作用权限控制和用户行为审计,堡垒机就像一个城堡的大门,城堡里的所有建筑就是你不同的业务系统 , 每个想进入城堡的人都必须经过城堡大门并经过大门守卫的授权,每个进入城堡的人必 ...
- Git配置安装使用教程操作github上传克隆数据
Git是何方神圣? Git是用C语言开发的分布版本控制系统.版本控制系统可以保留一个文件集合的历史记录,并能回滚文件集合到另一个状态(历史记录状态).另一个状态可以是不同的文件,也可以是不同的文件内容 ...
- 转:使用xhprof进行线上PHP性能追踪及分析
原文来自于:http://avnpc.com/pages/profiler-php-performance-online-by-xhprof 原创作者:AlloVince 之前一直使用基于Xdebug ...