牛客练习赛24-A 石子阵列

题目链接:https://www.nowcoder.com/acm/contest/157#question

这应该是比较水的题了吧,很简单。重m种石头中取n个,切相邻不同,那第一个有m种情况,以后都是m-1种情况。

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextInt();
		long m=sc.nextInt();
		
		long mod=1000000007;
		long ans=m%mod;
		for(int i=2;i<=n;i++) {
			ans*=(m-1);
			ans%=mod;
		}
		System.out.println(ans);
	}
}

猜你喜欢

转载自blog.csdn.net/King8611/article/details/81582678
今日推荐