Skip to content

Instantly share code, notes, and snippets.

@balamark
Created June 11, 2015 00:29
Show Gist options
  • Save balamark/8c47353d1841d1167ef9 to your computer and use it in GitHub Desktop.
Save balamark/8c47353d1841d1167ef9 to your computer and use it in GitHub Desktop.
ref
int solve(int p, int take, int num){
int &ret = dp[p][take][num];
if(p==n){
if(take>0 and num==0) return ret = 1;
return ret = 0;
}
if(ret!=-1) return ret;
int t = (num*10)+(s[p]-'0');
//take digit at position p or not
int a = solve(p+1, take+1, t%8);
int b = solve(p+1, take, num);
return ret = max(a,b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment