zoukankan      html  css  js  c++  java
  • Mutual Training for Wannafly Union #8 D

    Mr.BG is very busy person. So you have been given enough time (1000 milliseconds) to help him.

    Mr. BG has a bag of marbles with different alphabets written on them. And he has become busy on playing with these marbles by putting them in N boxes placed in a row. There are exactly M distinct type of marbles, N of each type.

    Now he puts only N marbles (out of M*N) in N boxes, one by one and upon completion he writes down the letters on the marbles on a paper to form a string. As Mr.BG hates palindrome strings (strings which read same from both sides e.g. MADAM), he erases palindrome string from the paper as soon as he finds one.

    Now he is wondering how many different strings he might get on his paper if he could try all possible combination of putting the marbles in the boxes. So you have to help him by answering. As there could be many strings so print it modulo 1,000,000,007.

    Input

    Input starts with an integer TC(<=10), denoting the number of test cases. Each case starts with two non negative integers N(<=100000) and M(<=26) as described above.

    Output

    For each case, print the case number and total number of strings written on the paper modulo 1000000007.

    Example

    Input:
    2
    2 2
    2 3
    Output:
    Case 1: 2
    Case 2: 6

    大佬给我们讲的题解,一句带过,我现在还不是很清楚那个公式是怎么来的,先标记下这个题目,m的n方-m的(n+1)/2次方,然后就是大数取余了,wa了一次,因为取余会出现负数,所以要先加上mod

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const LL mod=1e9+7;
    LL po(LL n,LL m){
    LL s=m%mod;
    for(LL i=1;i<n;i++)
    s=(s*m)%mod;
    return s;}
    int main(){
    int t,k=1;
    scanf("%d",&t);
    while(t--){
    LL n,m;
    scanf("%lld%lld",&n,&m);
    printf("Case %d: %lld
    ",k++,(po(n,m)-po((n+1)/2,m)+mod)%mod);
    }
    return 0;
    }
    
  • 相关阅读:
    任正非:所有公司都是管理第一,技术第二(没有一流管理,领先的技术就会退化;有一流管理,即使技术二流也会进步)
    QuickReport的OnNeedData的触发情况
    Quickreport不用数据字段,如何实现多页打印?
    我要继续做开发吗(对18个问题,全部都是肯定!)
    一台主机,至多可以开启多少个线程
    BenchmarkDotNet
    开发资源
    WebSocket
    TCP
    “在什么时候学习编程才合适?”
  • 原文地址:https://www.cnblogs.com/BobHuang/p/6775613.html
Copyright © 2011-2022 走看看