如果你测试点2和3TLE了……

P2415 集合求和

```cpp #include<bits/stdc++.h> using namespace std; long long nums[40]{},n,sums; long long get_sum(int bits) { long long temp=0,cnt=1; while(bits) { if(bits&1) temp+=nums[cnt]; bits>>=1; cnt++; } return temp; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long i=1; while(cin>>nums[i]) { i++; } n=i-1; long long maxn=(1<<n)-1; for(i=1;i<=maxn;++i) { sums+=get_sum(i); } cout<<sums; return 0; } ``` 这种只有60分,因为会TLE
by Cryflmind @ 2023-09-25 13:05:29


|