RT,自己写的理论空间复杂度上限 8×220 个long long,理论时间复杂度上限 40×220 但是一测有TLE有MLE,求大佬帮忙看看是我复杂度分析错了还是常数太大了
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
ll n,tx,ty,x[45],y[45],an[45];
struct hashfunc
{
size_t operator() (const pair<ll, pair<ll, ll> > &i) const
{
return hash<ll>()(i.first) ^ hash<ll>()(i.second.first) ^ hash<ll>()(i.second.second);
}
};
gp_hash_table<pair<ll,pair<ll,ll> >,ll,hashfunc> ma;
void dfs1(int no,pair<ll,ll> xy,int k){
if(no==n/2+1){
ma[{k,xy}]++;
return;
}
dfs1(no+1,xy,k);
dfs1(no+1,{xy.first+x[no],xy.second+y[no]},k+1);
}
void dfs2(int no,pair<ll,ll> xy,int k){
if(no==n+1){
for(int i=k;i<=n;++i){
an[i]+=ma[{i-k,{tx-xy.first,ty-xy.second}}];
}
return;
}
dfs2(no+1,xy,k);
dfs2(no+1,{xy.first+x[no],xy.second+y[no]},k+1);
}
int main(){
cin>>n>>tx>>ty;
for(int i=1;i<=n;++i){
cin>>x[i]>>y[i];
}
dfs1(1,{0,0},0);
dfs2(n/2+1,{0,0},0);
for(int i=1;i<=n;++i){
cout<<an[i]<<'\n';
}
return 0;
}
别问为啥不写双指针,问就是太长了懒得写