Buildings II

题目描述

As a traveling salesman in a globalized world, Alan has always moved a lot. He almost never lived in the same town for more than a few years until his heart yearned for a different place.
However, this newest town is his favorite yet - it is just so colorful. Alan has recently moved to Colorville, a smallish city in between some really nice mountains. Here, Alan has finally decided to settle down and build himself a home - a nice big house to call his own.
In Colorville, many people have their own houses - each painted with a distinct pattern of colors such that no two houses look the same. Every wall consists of exactly n × n squares, each painted with a given color (windows and doors are also seen as unique “colors”). The walls of the houses are arranged in the shape of a regular m-gon, with a roof on top. According to the deep traditions of Colorville, the roofs should show the unity among Colorvillians, so all roofs in Colorville have the same color.

Of course, Alan wants to follow this custom to make sure he fits right in. However, there are so many possible designs to choose from. Can you tell Alan how many possible house designs there are? (Two house designs are obviously the same if they can be translated into each other just by rotation.)

输入

The input consists of:
• one line with three integers n, m, and c, where
– n (1 ≤ n ≤ 500) is the side length of every wall, i.e. every wall consists of n × n squares;
– m (3 ≤ m ≤ 500) is the number of corners of the regular polygon;
– c (1 ≤ c ≤ 500) the number of different colors.

输出

Output s where s is the number of possible different house designs. Since s can be very large,output s mod (109 + 7).

样例输入

1 3 1

样例输出

1

【题解】

【队友代码】

 #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("O3")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
#define pi acos(-1.0)
#define nl "\n"
#define pii pair<ll,ll>
#define ms(a,b) memset(a,b,sizeof(a))
#define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
ll qpow(ll x, ll y){ll s=;while(y){if(y&)s=s*x%mod;x=x*x%mod;y>>=;}return s;}
//ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
inline int read(){int x=,f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<='') x=x*+ch-'',ch=getchar();return x*f;} int n, m, c;
ll p[]={}; int main()
{
scanf("%d%d%d",&n,&m,&c);
ll k = qpow(c,n*n);
for(int i=;i<=m;i++) p[i] = p[i-]*k%mod;
ll ans = ;
for(int i=;i<=m;i++) ans = (ans+p[__gcd(m,i)])%mod;
//cout<<ans<<nl;
ans = ans*qpow(m,mod-)%mod;
printf("%lld\n",ans);
return ;
}

【Polya计数】Buildings II的更多相关文章

  1. 《程序设计中的组合数学》——polya计数

    我们在高中的组合数学中常常会碰到有关涂色的问题,例如:用红蓝两种颜色给正方形的四个顶点涂色,会有几种不同的方案.在当时,我们下意识的认为,正方形的四个顶点是各不相同的,即正方形是固定的.而实际上我们知 ...

  2. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  3. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. Polya计数

    Let it Bead Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5365   Accepted: 3585 Descr ...

  5. 组合数学及其应用——polya计数

    在处理类似下面的问题中,一般的计数方法会出现问题:假如你要用红.蓝两种颜色给一个正四面体的四个顶点着色,试问存在多少种不同的着色方案? 在高中我们常用的方法是模拟涂色过程,分情况讨论,然后基于分步乘法 ...

  6. HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)

    Who's Aunt Zhang Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 5868:Different Circle Permutation 【Polya计数】

    似乎是比较基础的一道用到polya定理的题,为了这道题扣了半天组合数学和数论. 等价的题意:可以当成是给正n边形的顶点染色,旋转同构,两种颜色,假设是红蓝,相邻顶点不能同时为蓝. 大概思路:在不考虑旋 ...

  8. 群论&Polya计数

    群论&Polya计数 其实在我听课的过程中,我发现针对于学习OI中的群并没有什么过多必要向内学习... 群 以后会补的. 就是\(QQ\)群. 置换 置换就是一个... \[ \begin{m ...

  9. [置换群&Polya计数]【学习笔记】

    昨天看了一下午<组合数学>最后一章然后晚上去看别人的blog发现怎么都不一样,我一定是学了假的polya 其实是一样的,只不过<组合数学>没有太多的牵扯群论.于是又从群论角度学 ...

随机推荐

  1. TCP/IP 这猝不及防的爱情

    前言 前几天看了老刘的一篇文章,TCP/IP 大明邮差.正好最近也在读<计算机自顶向下>一书 心血来潮,想写一个女版的TCP/IP 正文 一天,我正在百花会上赏花,赏着赏着,就出现了一个令 ...

  2. docker.socks vul

    在容器上获取 RCE 1)列出所有容器 第一步是获取主机上所有容器的列表.为此,你需要执行以下http请求: GET /containers/json HTTP/1.1 Host: <docke ...

  3. Java 面向对象(三)

    封装 什么是封装 面向对象三大特征之一 1. 把对象的状态和行为看成一个统一的整体,将字段和方法放到一个类中. 2. 信息隐藏:把不需要让外界知道的信息隐藏起来.尽可能隐藏对象功能实现细节,向外界暴露 ...

  4. android: View, SurfaceView, GLSurfaceView, TextureView 区别与联系

    区别与联系 View: 显示视图,内置画布,提供了图形绘制函数.触屏事件.按键事件函数等,必须在UI主线程内更新画面,速度较慢: SurfaceView: 基于view视图进行拓展的视图类,更适合2D ...

  5. element ui组件的开始时间-结束时间验证

    <el-date-picker v-model="seach.before" type="date" placeholder="开始时间&quo ...

  6. rand随机函数

    1.rand() rand()函数是使用线性同余法做的,它并不是真的随机数,因为其周期特别长,所以在一定范围内可以看成随机的. rand()函数不需要参数,它将会返回0到RAND_MAX之间的任意的整 ...

  7. 《高性能mysql》笔记(第一章,mysql的架构与历史)

    mysql的服务器逻辑架构图如下: 目前工作用的5.5版本,5.5版本开始mysql开始将innoDB作为默认的存储引擎,innoDB的表是基于聚簇索引建立的. mysql的存储引擎锁管理非常重要,在 ...

  8. 【转载】 AutoML技术现状与未来展望

    原文地址: https://www.cnblogs.com/marsggbo/p/9309520.html ---------------------------------------------- ...

  9. ideal配置使用Git

    1.git简介 git是目前流行的分布式版本管理系统.它拥有两套版本库,本地库和远程库,在不进行合并和删除之类的操作时这两套版本库互不影响.也因此其近乎所有的操作都是本地执行,所以在断网的情况下任然可 ...

  10. (十一)使用Jconsole监控线程

    一.案例 监控线程情况,包括阻塞.死循环等 1.1 代码如下,下述代码共有三个线程,Main.mythread01.mythread02线程,其中mythread01线程为死循环.mythread02 ...