zoukankan      html  css  js  c++  java
  • 【五校联考7day1】n染色

    考试时乱推了好久,搞啊搞啊的。。。
    咣咣的。。。。
    上标:

    #include<cstdio>
    #define ll long long
    #define mo 1000000007
    using namespace std;
    ll n,m,s,v,k,g,p,ans,t,y;
    
    ll ksm(ll x,ll y)
    {
    	ll s=1;
    	while (y)
    	{
    		if (y & 1) s=s*x%mo;
    		x=x*x%mo,y>>=1;
    	}
    	return s;
    }
    
    int main()
    {
    	freopen("color.in","r",stdin);
    	freopen("color.out","w",stdout);
    	scanf("%lld%lld",&n,&m);
    	//
    	if (m==2) return 0&puts("2");
    //	这句话本来是不用加的,但是数据?的有问题,所以不得不加上
    //	为了AC! 
    	//
    	s=3*(m-3)+1;v=t=y=6;k=g=18;
    	for (int i=m-4;i>=0;i--)
    		v+=k,k+=g,g+=6,t+=y,y+=2;
    	for (int i=m-4;i>0;i--) s+=(m-i-1)*i;
    	s=s*6%mo;
    	p=(m-1)*(m-1);
    	ans=ksm(p,(n-3)/2)*s%mo+v*(ksm(p,(n-3)/2)+mo-1)/(p-1)%mo;
    	if (!(n & 1)) ans=(ans*(m-1)%mo+t)%mo;
    	printf("%lld
    ",ans);
    	return 0;
    }
    

    正解有点假(骚):
    答案就是:(m-1)n-(m-1)*(-1)n
    上标:

    #include<cstdio>
    #define ll long long
    #define mo 1000000007
    using namespace std;
    ll n,m,ans=0;
    int a[100010];
    
    ll ksm(ll x,ll y)
    {
    	ll s=1;
    	while (y)
    	{
    		if (y & 1) s=s*x%mo;
    		x=x*x%mo,y>>=1;
    	}
    	return s;
    }
    
    int main()
    {
    	freopen("color.in","r",stdin);
    	freopen("color.out","w",stdout);
    	scanf("%lld%lld",&n,&m);
    	ans=ksm(m-1,n)+(m-1)*ksm(-1,n);
    	printf("%lld
    ",ans%mo);
    	return 0;
    }
    
    转载需注明出处。
  • 相关阅读:
    跨域踩坑经验总结(内涵:跨域知识科普)
    Nginx location规则匹配
    CentOS 命令
    Centos 修改源
    Ubuntu下获取内核源码
    Ubuntu用户自定义脚本开机启动
    ubuntu 14.04安装x11VNC
    texi格式文件的读取
    更换主机后SSH无法登录的问题
    ubuntu操作系统的目录结构
  • 原文地址:https://www.cnblogs.com/jz929/p/11817604.html
Copyright © 2011-2022 走看看