• 【Polya计数】Buildings II


     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



    【题解】

    【队友代码】

     1 #pragma GCC optimize("Ofast,no-stack-protector")
     2 #pragma GCC optimize("O3")
     3 #pragma GCC optimize(2)
     4 #include <bits/stdc++.h>
     5 #define inf 0x3f3f3f3f
     6 #define linf 0x3f3f3f3f3f3f3f3fll
     7 #define pi acos(-1.0)
     8 #define nl "
    "
     9 #define pii pair<ll,ll>
    10 #define ms(a,b) memset(a,b,sizeof(a))
    11 #define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
    12 using namespace std;
    13 typedef long long ll;
    14 const ll mod = 1e9+7;
    15 ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
    16 //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;}
    17 inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
    18   
    19 int n, m, c;
    20 ll p[505]={1};
    21   
    22 int main()
    23 {
    24     scanf("%d%d%d",&n,&m,&c);
    25     ll k = qpow(c,n*n);
    26     for(int i=1;i<=m;i++) p[i] = p[i-1]*k%mod;
    27     ll ans = 0;
    28     for(int i=1;i<=m;i++) ans = (ans+p[__gcd(m,i)])%mod;
    29     //cout<<ans<<nl;
    30     ans = ans*qpow(m,mod-2)%mod;
    31     printf("%lld
    ",ans);
    32     return 0;
    33 }
    View Code
  • 相关阅读:
    【解决办法】移动硬盘在电脑上显示“本地磁盘”并且出现打不开的情况
    在Windows上搭建Python环境
    Thymeleaf模板的使用
    thymeleaf中的th:remove用法
    AngularJS PhoneCat代码分析
    AngularJS PhoneCat代码分析
    利用java反射调用类的的私有方法--转
    Java Reflection (JAVA反射) --转载
    Eclipse 常用快捷键 (动画讲解)--转载
    三大JavaScript框架对比——AngularJS、BackboneJS和EmberJS
  • 原文地址:https://www.cnblogs.com/Osea/p/11397623.html
Copyright © 2020-2023  润新知