牛客练习赛24---A

        假设有n个位置需要我们去放石子,那么第一个位置我们可以放m个石子,而之后的每一个位置放的位置都要和前一个不同,那么每一个位置都有m-1个类型的石子可以放,那么答案就是,(m-1)*(n-1)+m 个石子

代码如下

#include <bits/stdc++.h>
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
using namespace std;
typedef long long LL;
int gcd(int a,int b){if (b == 0) return a; return gcd(b , a%b);}
int lcm(int a, int b){ return a/gcd(a,b)*b;}
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48); ch=getchar();}
    return x*f;
}
const int mod = 1000000007;
int main(){
    int n,m;
    sc2(n, m);
    LL ans = m;
    for (int i=2; i<=n; i++) {
        ans = (m-1) * ans % mod;
    }
    printf("%lld\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/CCCCTong/article/details/81583835