本文亦发表于笔者博客:https://www.codein.icu/nowcoderweekly19/

A

考虑选出每个人当队长时,被选数组的方案数为多少。
每个人状态有2种:选与不选,而选定队长必须选,因此有 种包含该人且为队长的选人方案。
总方案数即为 ,注意取模即可。

#include <cstdio>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int mod = 1e9 + 7;
long long n;
inline long long fastpow(long long x,long long k)
{
    long long res = 1;
    while(k)
    {
        if(k & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        k >>= 1;
    }
    return res % mod;
}
int main()
{
    read(n);
    printf("%lld\n",(n * fastpow(2,n - 1)) % mod);
    return 0;
}