杭電 hdu 2502

月之數:

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int m;
        cin>>m;
        int count=0;
        count+=pow(2.0,m-1)+(m-1)*(pow(2.0,m-1))/2;
        cout<<count<<endl;
    }
    return 0;
}

當n=4時,有:
1000
1001
1010
1011
1100
1101
1110
1111
可以看到。除了第一位剩下的有
000
001
010
011
100
101
110
111
可以數一下,0和1的總個數一半對一半。於是算一下0和1總個數,除以2就好了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章