zoukankan      html  css  js  c++  java
  • 手环定理

    手环定理 :

    一个手环是由n个珠子构成,有k种颜色,每个珠子可以染成这k种颜色中的任意一种,求可以染出多少种本质上不相同的手环来(这里需要考虑手环旋转后仍是同一种手环);

    定理公式为:

    方案数:L  =  inv(G)* ( k^c[0]  +  k^c[1]  +  ........  + k^c [ G-1 ])

    其中G是我们要染色的手环的长度(珠子的个数),k是我们有多少种颜色,c[i]=__gcd[i,n];

    注意算一下取模

    题目如下:

    问题 A: Buildings II

    时间限制: 1 Sec  内存限制: 128 MB

    题目描述

    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

    题意:有一个柱体有m个面每个面上有n×n个格子,现在有c种颜色,最多可以染成本质不同的柱体.

    根据手环定理 得,有一个长度是m的手环,现在有( c ^(n^2))种颜色,我们最多可以染成多少种不相同的手环.

    G=m, K=c^(n^2),c[i]=gcd(i,m);  i=(0~m-1)

    代码如下:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll ;
     4 const int N = 3e5+5;
     5 const int mod=1e9+7;
     6 ll  pow_mod(ll  a, ll  b)
     7 {
     8     ll  ret = 1;
     9     while(b){
    10         if(b & 1) ret = (ret * a) % mod;
    11         a = (a * a) % mod;
    12         b >>= 1;
    13     }
    14     return ret%mod;
    15 }
    16 int main()
    17 {
    18     int n,m,c;
    19     scanf("%d%d%d",&n,&m,&c);
    20     ll  k=pow_mod(c,n*n);
    21     ll oo=0;
    22     for(int i=0;i<=m-1;i++)
    23     {
    24         oo=oo+(pow_mod(k,__gcd(i,m))%mod);
    25 oo%=mod; 26 } 27 ll res=(pow_mod(m,mod-2)%mod)*oo%mod; 28 printf("%lld ",res); 29 30 return 0; 31 }

    参考链接:https://blog.csdn.net/qq_39792342/article/details/82011045

  • 相关阅读:
    迭代
    UIViewController生命周期控制
    JPA相关注解
    正則表達式截取字符串两字符间的内容
    HDU 1789 Doing Homework again
    《从零開始学Swift》学习笔记(Day48)——类型检查与转换
    POJ 3280 Cheapest Palindrome(区间DP)
    JavaScript高级特性之原型
    http协议
    编程算法
  • 原文地址:https://www.cnblogs.com/sylvia1111/p/11372673.html
Copyright © 2011-2022 走看看