Beijing University of Science and Technology Information eleventh Programming Contest (to reproduce the race) B

B Kotori and balloons

Topic links: https://ac.nowcoder.com/acm/contest/940/B

Title Description

kotori recently fell in love swing balloon game. She a total of n kinds of balloons, each balloon there are numerous. She put to come up with a number of balloons in a row.

However, since the balloon was cast magic, the same type of balloon if the adjacent explode, so if two adjacent balloons of the same kind are not considered legitimate.

kotori want to know, put a row of m, a total of how many different programs?

Since this number may be too large, you need to output only the result of modulo 109.


Enter a description:

Input only one row, two integers n and m (1≤n, m≤100)

Output Description:

Output an integer, the result is a number of programs modulo 109.
Example 1

Entry

3 2

Export

6

Explanation

Suppose three kinds of labeled 1,2,3 balloon, then a total of six kinds of the following schemes: [1,2] [1,3] [2,1] [2,3] [3,1] [3,2].

 

Ideas:

  The first option has n possible, choose a second n-1 possible, choose a third possible n-1, n-1 is later possible
number of programs so that n * (n-1) * (n-1) * ....



#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll maxn=109;
ll jie(ll n,ll m)
{
    ll result1=1;
    for(int i=0;i<m-1;i++)
    {
       result1*=(n-1);
        result1=result1%maxn;
 
    }
    return n*result1%maxn;
}
 
int main()
{
    ll n,m;
    while(cin>>n>>m)
    {
        cout<<jie(n,m)%maxn<<endl;
    }
    return 0;
}

 





Guess you like

Origin www.cnblogs.com/Vampire6/p/11131666.html