http://oj.xjtuacm.com/problem/21/
对13进行分析,每种价格出现的次数:
$(C_m^1 + C_m^2 + ... + C_m^m)(C_{n - m}^0 + C_{n - m}^1 + C_{n - m}^2 + ... + C_{n - m}^{n - m}) = ({2^m} - 1)*{2^{n - m}} = {2^n} - {2^m}$
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<iostream> 6 #include<cmath> 7 using namespace std; 8 typedef long long ll; 9 int a[1000],num[20]; 10 int main(){ 11 int t; 12 cin>>t; 13 while(t--){ 14 memset(num,0,sizeof num); 15 int n; 16 cin>>n; 17 for(int i=0;i<n;i++){ 18 cin>>a[i]; 19 } 20 for(int i=0;i<n;i++){ 21 num[a[i]]++; 22 } 23 int sum=0; 24 for(int i=0;i<=13;i++){ 25 if(num[i]>=1) sum+=i*(pow(2,n)-pow(2,n-num[i])); 26 } 27 cout<<sum<<endl; 28 } 29 }