#include <cstdio>#include <cstring>#include <algorithm>usingnamespacestd;
constint mod = 1e9 + 7;
int N, K;
longlong pow_mod(longlong x, int n) {
if (n < 0) return0;
longlong ret = 1;
while (n) {
if (n&1) ret = ret * x % mod;
x = x * x % mod;
n >>= 1;
}
return ret;
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d%d", &N, &K);
if (N == K) {
printf("1\n");
continue;
}
int ans = pow_mod(2, N-K);
ans = (ans + pow_mod(2, N-K-2) * (N-K-1)) % mod;
printf("%d\n", ans);
}
return0;
}
题目链接:hdu 4602 Partition代码#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int mod = 1e9 + 7;int N, K;long long pow_mod(long long x, int n) { if (n < 0) return 0;