2466: 【普及-】【P2415】集合求和

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:4 解决:2

题目描述

给定一个集合 lns="http://www.w3.org/1998/Math/MathML">(集合元素数量 lns="http://www.w3.org/1998/Math/MathML">30),求出此集合所有子集元素之和。

输入

集合中的元素(元素 lns="http://www.w3.org/1998/Math/MathML">1000

输出

 所有子集元素之和。

样例输入 复制

2 3

样例输出 复制

10

提示

【样例解释】

子集为:lns="http://www.w3.org/1998/Math/MathML">,{2},{3},{2,3},和为 lns="http://www.w3.org/1998/Math/MathML">2+3+2+3=10


【数据范围】

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">130lns="http://www.w3.org/1998/Math/MathML">11000lns="http://www.w3.org/1998/Math/MathML"> 所有子集元素之和 lns="http://www.w3.org/1998/Math/MathML">1018

#include<bits/stdc++.h>
using namespace std;
int n,t;
long long ans;
int main(){
    while (cin>>t) {
    	ans+=t;
    	n++;
	}
    for (int i=1;i<n;i++)
        ans*=2;
    cout<<ans;
	return 0;
}
/**
设n为个数:
n=1 数列:1     ans=1*1
n=2 数列:1 2   ans=1+2+1+2=(1+2)*2
n=3 数列:1 2 3 ans=(1+2+3)+(1+2+1+3+2+3)+(1+2+3)=(1+2+3)*4
所以,ans=ans*2^(n-1);
**/