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. 2019-12-11:kali linux工具Msfvenom 命令自动补全

    msfvenom大家都不陌生,在我们使用MSF进行权限维持,内网渗透的时候都会用到,支持的语言的种类很多.大家都知道我们在使用msfvenom 的时候需要手动输入很多参数,这些参数需要记忆,或记在其它 ...

  2. 小程序can't read property 'push' of undefined

    在某些情况下是因为没有初始化,所以初始化一下就好了

  3. php手记之05-tp5模型操作数据库

    # 实例化模型 // $user = new User; // $user1 = new User(); // $user2 = model('user'); // 添加一条数据 # 方法1 // $ ...

  4. 【Oracle/Java】批量删除16张十万数据的表 单线程耗时45秒 多线程耗时38秒

    昨天做了插入的单线程多线程比较,今天做个删除的. 单线程批量删除类代码: package com.hy.delete.singlethread; import java.sql.Connection; ...

  5. 如何确认oracle客户端中的TNSNAMES中的service_name

    在我们安装oracle的客户端,或者PLSQL develop的时候,需要在oracle的安装目录下修改TNSNAME中配置你要连接的数据库的TNS参数.配置好了可以通过命令行使用tnsping命令测 ...

  6. pgpool 的配置文件详解

    listen_addresses = 'localhost' # Host name or IP address to listen on: # '*' for all, '' for no TCP/ ...

  7. vue elementUI 表单校验(多层嵌套)

    <template> <el-form :model="formData" :rules="formRule" ref="formD ...

  8. ISO/IEC 9899:2011 条款6.2.8——对象的对齐

    6.2.8 对象的对齐 1.完整的对象类型具有对齐要求,对齐要求是对该类型对象可以在哪个地址进行分配的放置限制.一个对齐是一个实现定义的整数值,表示一个给定对象可以分配在相继两个地址之间跨多少字节的位 ...

  9. linux下程序启动后后台运行实现

    关于linux下的程序运行很简单,将源码编译成二进制(假设为proram)文件后直接在命令行运行即可,root#./program如果需要后台运行,即不占用当前终端,这在嵌入式linux显得十分有必要 ...

  10. flutter的生命周期

    大致可以看成三个阶段 初始化(插入渲染树) 状态改变(在渲染树中存在) 销毁(从渲染树种移除) initState 当插入渲染树的时候调用,这个函数在生命周期中只调用一次.这里可以做一些初始化工作,比 ...