Skip to content

Instantly share code, notes, and snippets.

@enzerr
Created April 3, 2023 00:15
Show Gist options
  • Save enzerr/e7702077827558d3ed33ee872eb1774d to your computer and use it in GitHub Desktop.
Save enzerr/e7702077827558d3ed33ee872eb1774d to your computer and use it in GitHub Desktop.
class Solution {
public:
int cnt[10], ans = 1e6;
vector<int> cks;
void dp(int id, int k){
if(id==cks.size()){
int tans = 0;
for(int i = 0; i < k; i++) tans = max(tans, cnt[i]);
ans = min(ans, tans);
}
else{
for(int i = 0; i < k; i++){
cnt[i] += cks[id];
dp(id+1, k);
cnt[i] -= cks[id];
}
}
}
int distributeCookies(vector<int>& cookies, int k) {
cks = cookies;
dp(0, k);
return ans;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment