找规律,推公式,快速幂
2 4 2 5 5
5 1
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int LL;
const long long int MOD=1e9+7;
LL POW2(int x)
{
LL ret=1LL;
LL e=2LL;
while(x)
{
if(x&1) ret=ret*e%MOD;
e=e*e%MOD;
x>>=1;
}
return ret%MOD;
}
int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
int a,b,t;
scanf("%d%d",&a,&b);
t=a-b;
if(t<0)
{
printf("0\n"); continue;
}
else if(t==0)
{
printf("1\n"); continue;
}
else if(t==1)
{
printf("2\n"); continue;
}
else if(t==2)
{
printf("5\n"); continue;
}
else printf("%I64d\n",((t+3)%MOD*POW2(t-2)%MOD)%MOD);
}
return 0;
}
HDOJ 4602 Partition,布布扣,bubuko.com
原文:http://blog.csdn.net/u012797220/article/details/21051471