http://acm.hdu.edu.cn/showproblem.php?pid=4602
可以发现,1的拆分里面有1个1,2有2个1,3有5个1,4有12个1,
形成一个数列:1,2,5,12,28,64。。。
然后2的拆分里有1个2,3有2个2,4有5个2,
又是这个数列:1,2,5,12,28,64。。。
记f(n)为N的拆分中有多少个1。。
n>=3时 , f(n)=f(n-1)*2+2^(n-3)
N的拆分中有f(n-k+1)个k。
可以推出 f(n)=(n+2)*2^(n-3)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll powmod(int a,int b)
{
if(b==0) return 1;
if(b==1) return a%mod;
ll t=powmod(a,b/2)%mod;
t=t*t%mod;
if(b%2==1) t=t*a%mod;
return t;
}
int n,k;
int main()
{
//cout<<powmod(10000,1000);
int re; cin>>re;
while(re--)
{
cin>>n>>k;
if(k>n) { cout<<0<<endl; continue; }
n=n-k;
ll ans=1;
if(n==0) ans=1;
else {
if(n==1) ans=2;
else ans=(n+3)*1ll*powmod(2,n-2)%mod;
}
cout<<ans<<endl;
}
}