且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

hdu 2502

更新时间:2022-08-13 08:58:01

http://acm.hdu.edu.cn/showproblem.php?pid=2502
当n=4时;
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
注意1的个数就是前面的1加上后面的1
所以公式:
ans=2^(n-2)*(n-1) + 2^(n-1);

#include <iostream>

using namespace std;

int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int ans=(n-1)*(1<<(n-2))+(1<<(n-1));
        cout<<ans<<endl;
    }
    return 0;
}