暑假集训7月20日(距离结训赛26天)
作者:互联网
K - Subarrays OR
类似DP,前缀和#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int>pii; const int N=1e5+10; int n; set<ll> preans,nowans,ans; signed main() { int t; cin>>t; while(t--) { ans.clear(); preans.clear(); cin>>n; for (int i=1; i<=n; i++) { ll x; cin>>x; nowans.clear(); nowans.insert(x); ans.insert(x); for (auto y:preans) { nowans.insert(x|y); ans.insert(x|y); } preans=nowans; } cout<<ans.size()<<"\n"; } return 0; }
最近在搞DFS,虽然DFS暴搜不能过,但是调出来就不错了,卑微
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int>pii; const int N=1e5+10; unordered_map<ll,bool>mp; ll a[N]; int n; void dfs(int u,ll num,int backpos) { if (!backpos) { return; } if (backpos) { num=num|a[u]; mp[num]=1; backpos--; dfs(u+1,num,backpos); } } signed main() { int t; cin>>t; while(t--) { mp.clear(); cin>>n; for (int i=1; i<=n; i++) cin>>a[i]; for (int i=1; i<=n; i++) { int backpos=n-i+1; dfs(i,a[i],backpos); } cout<<mp.size()<<"\n"; } return 0; }
标签:26,20,int,nowans,num,结训,ans,ll,backpos 来源: https://www.cnblogs.com/Mercury1988/p/16496914.html