题目:
题意:
求用 m m m中颜料对一个 n n n边形的图形进行染色,并相邻的边的颜色不同,求总方案数
分析:
打个表,找个规律
然后怒切
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define LL long long
#define mo 1000000007
using namespace std;
using namespace __gnu_pbds;
inline LL read(){
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
LL n,m;
LL ksm(LL x,LL y)
{
LL s=1;
while(y)
{
if(y%2==1) (s*=x)%=mo;
y/=2;
(x*=x)%=mo;
}
return s%mo;
}
int main()
{
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
n=read(),m=read();
cout<<ksm(m-1,n)+(m-1)*ksm(-1,n);
return 0;
}