知识点:
先选出指定的一个元素,加入子集;
首先,当子集里只有一个元素时,在其他剩余的元素中不能选出任何元素加入到子集中,所以对于每个元素来说,均有次被选中。
当子集里有2个元素时,在其他剩余的元素中选出1个元素加入到子集中,所以对于每个元素来说,均有 次被选中。
当子集里有3个元素时,在其他剩余的元素中选出2个元素加入到子集中,所以对于每个元素来说,均有次被选中。
当子集里有i(i\leqn)个元素时,在其他剩余的元素中选出i-1个元素加入到子集中,所以对于每个元素来说,均有次被选中。
所以共有次被选中,即次被选中。
#include<iostream>
#include <cstdio>
#include<cmath>
using namespace std;
int a[31],i=0,j;
long long s=0;
int read(){
int x = 0,f = 1;
char c = getchar();
while (c<'0'||c>'9') {
if (c=='-') {
f = -1;
}
c = getchar();
}
while (c>='0'&&c<='9') {
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
long long qmi(int m, int k)
{
int res = 1, t = m;
while (k)
{
if (k&1) res = res * t;
t = t * t;
k >>= 1;
}
return res;
}
int main(){
//cout<<s;
while(cin>>a[i++]);//合写cin>>a[i];i++;
for(j=0;j<i;j++){
s+=a[j];
}
s *= qmi(2,i-2);//注意,i-2!
cout<<s;
return 0;
}
/*
6
91 67 80
78 89 98
78 89 91
88 99 77
67 89 64
90 66 82
============
6 265
4 264
3 258
2 244
1 237
*/
网友评论