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;
    }
    
    转载需注明出处。
  • 相关阅读:
    移动端上拉下拉刷新组件
    linux ftp搭建
    asp.net core 在Ubuntu 运行
    go can't find import: "github.com/** 错误
    WPF
    总结
    ASP.net
    计算器简单封装和ASP.net
    用户故事
    四则运算.结对编程
  • 原文地址:https://www.cnblogs.com/jz929/p/11817604.html
Copyright © 2011-2022 走看看