用n种颜色给正方体着色共用多少种不同的着色方案

来源:互联网 发布:linux有什么认证 编辑:程序博客网 时间:2024/05/29 10:38



http://exam.upc.edu.cn/problem.php?id=4200


题目大意:

用n种颜色给正方体着色共用多少种不同的着色方案


分析:

根据Polya定理可求得(并不会推只知道公式学会了再来解释)

 res=(n^6 + 3*n^4 + 12*n^3 + 8*n^2)/24 



AC代码:

#include <stdio.h>#include <math.h>  #include <stdlib.h>  #include <string.h>  #include <time.h>  #include <iostream>  #include <algorithm> #include <string>#include <queue>   #include <stack>  #include <vector>#include <set>  #include <list>  #include <map>#define mset(a,i) memset(a,i,sizeof(a))#define SS(s)     scanf("%s",s)#define S1(n)     scanf("%d",&n)#define S2(n,m)   scanf("%d%d",&n,&m)#define P(n)      printf("%d\n",n)#define FIN       freopen("input.txt","r",stdin)#define FOUT      freopen("output.txt","w",stdout)#define gcd(a,b)  __gcd(a,b)using namespace std;typedef long long ll;const double eps=1e-6;const int INF=0x3f3f3f3f;const int mod=1e9+7;const int MAX=1e6+5;const double PI=acos(-1);int dir[5][2]={0,1,0,-1,1,0,-1,0};ll qpow(ll n,ll m){n%=mod;ll ans=1;while(m){if(m%2) ans=(ans*n)%mod;m/=2;n=(n*n)%mod;}return ans;}ll inv(ll b){return b==1?1:(mod-mod/b)*inv(mod%b)%mod;}ll inv2(ll b){return qpow(b,mod-2);}int main(){int n;ll ans1;while (scanf ("%d",&n)!=EOF){ans1=0;ans1=((((qpow(n,6)%mod+3*qpow(n,4)%mod)%mod+12*qpow(n,3)%mod)%mod+8*qpow(n,2)%mod)%mod*inv(24))%mod;printf ("%lld\n",ans1);}return 0;} 






原创粉丝点击