计蒜客-修建公路

题目链接 https://nanti.jisuanke.com/t/A2224

 n=2019的时候,最小代价是1+2+3...+2018,对于每个i,计算其二进制有t个1,则可以与其相连的点有2^t-1个

(具体题解参考视频https://www.jisuanke.com/course/1980/162840

#include <cstdio>
using namespace std;
typedef long long ll;
int bit_count(int x) {
    int res = 0;
    for(int i = 0;i < 32;i++) {
        if(x&(1<<i)) res++;
    }
    return res;
}
ll res = 1;

ll MOD = 1e9 + 7;

int main()
{
   for(int i = 1;i < 2019;i++) {
        int t = bit_count(i);
        res = (res * ((1<<t)-1)) % MOD;
   } 
    
    printf("%lld\n",res);
    
    return 0;
} 

猜你喜欢

转载自blog.csdn.net/lmhlmh_/article/details/87435608