feat: 添加子集和计算功能

实现通过位运算计算子集和并统计出现次数
This commit is contained in:
Zengtudor 2025-11-13 19:03:43 +08:00
parent 71bb5fe79f
commit f6d958f00a

View File

@ -2,10 +2,12 @@
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <istream> #include <istream>
#include <map>
#include <unordered_map>
#include <vector> #include <vector>
using ll = int64_t; using ll = int64_t;
ll n,b; ll n,b,ans;
struct P{ struct P{
ll x,y; ll x,y;
inline bool operator<(const P&o)const{ inline bool operator<(const P&o)const{
@ -16,6 +18,7 @@ struct P{
} }
}g; }g;
std::vector<P> a; std::vector<P> a;
std::unordered_map<ll,std::unordered_map<ll,ll>> m;
int main(){ int main(){
std::iostream::sync_with_stdio(false); std::iostream::sync_with_stdio(false);
@ -36,6 +39,17 @@ int main(){
} }
return 0; return 0;
} }
b=(n+1)/2; b=n/2+1;
for(ll tmp=1;tmp<(1ull<<(b-1));tmp++){
ll ax=0,ay=0;
for(ll j=0;j<b-1;j++){
if(tmp&(1ll<<j)){
const ll nj=j+1;
ax+=a[nj].x;
ay+=a[nj].y;
}
}
m[ax][ay]++;
}
// for(ll msk=1;msk<(1ull<<(n-b)))
} }