dp with bitsets

iam trying to solve a dp problem using maps as follows -

#include<bits/stdc++.h>
using namespace std;
#define M 100000;

map< pair<bitset<100000>,int> , int > dp;

int n,k,ans;
bitset<100000> bs,ans_set;

int maxset(bitset<100000> gp,int k){
if(k==0){
int curans = INT_MIN,cur=0;
for(int i=0;i<n;i++){
if(gp[i]&1)cur++;
else {
curans = max(curans,cur);
cur = 0;
}
}

if(ans < curans){
ans=curans;
ans_set=gp;
}

return curans;
}

// lookup
if(dp.find({gp,k}) != dp.end()) return dp[{gp,k}];

for(int i=0;i<n;i++){
if( (gp[i]&1) == 0 ){
dp[{gp,k}]=max(dp[{gp,k}],maxset(gp,k-1));
}
}
return dp[{gp,k}];
}


int main(){
cin>>n>>k;
int x;
for(int i=0;i<n;i++){cin>>x;
bs[n-i-1]=x;
}
cout<<ans<<endl<<ans_set;
}

Getting unusual error . Can anyone tell , what's wrong with the code?
You need to define operator< to compare the map elements.

It's unlikely you want the semicolon in your definition of M (although you never use M so it currently doesn't matter).

And you probably want to call maxset from main at some point.

Finally, next time post your code in code tags and be more specific with your question.
Last edited on
Topic archived. No new replies allowed.