(HDU 5793)2016 Multi-University Training Contest 6 A Boring Question (规律)

思路

打表发现规律。。
对于 m 相同时,答案是以 m 为比的等比数列的和
ans=mn+11m1

打表代码

#include 
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=a;i
#define debug(a) printf("a =: %d\n",a);
const int INF=0x3f3f3f3f;
const int maxn=1e6+50;
const int Mod=1000000007;
const double PI=acos(-1);
typedef long long ll;
using namespace std;

int n,m;

ll sum=0;

ll jc(ll x){
    ll ret=1;
    for(ll i=2;i<=x;i++) ret=ret*i;
    return ret;
}
ll get(ll kj1,ll kj){
    return jc(kj1)/jc(kj)/jc(kj1-kj);
}
void dfs(int dep,vector<int> v,int cur){
    if (dep==m){
        ll ret=1;
        for(int i=0;i1;i++){
            ret=ret*get(v[i+1],v[i]);
        }
      //  cout<
        sum+=ret;
        return;
    }else if (dep>m) return;
    for(int i=cur;i<=n;i++){
        vector<int> vv(v);
        vv.push_back(i);
        dfs(dep+1,vv,i);
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
    #endif

    for(m=1;m<=10;m++)
        for(n=1;n<=10;n++){

        sum=0;
        vector<int> v;

        dfs(0,v,0);


        cout<" "<" "<return 0;
}

代码

#include 
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=a;i
#define debug(a) printf("a =: %d\n",a);
const int INF=0x3f3f3f3f;
const int maxn=1e6+50;
const int Mod=1000000007;
const double PI=acos(-1);
typedef long long ll;
using namespace std;

int n,m;

// n m
// m^0+m^1+...+m^n

ll qPow(ll x,ll n){
    ll ret=1;
    while(n){
        if (n&1) ret=(ret*x)%Mod;
        x=(x*x)%Mod;
        n>>=1;
    }
    return ret;
}

ll solve(){
    ll fz=(qPow(m,n+1)-1+Mod)%Mod;

    ll fmr=qPow(m-1,Mod-2);

  //  cout<
    return (fz*fmr)%Mod;
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
    #endif
    int T; scanf("%d",&T);
    while(T--){
        scanf("%d %d",&n,&m);
        printf("%lld\n",solve());
    }





    return 0;
}

你可能感兴趣的:(水题库)