Skip to content

Commit

Permalink
Update 2305.Fair-Distribution-of-Cookies_v2.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Jun 13, 2022
1 parent ca84944 commit f9d6452
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ class Solution {
return left;
}

bool dfs(vector<int>& cookies, int limit, int k, int idx)
bool dfs(vector<int>& cookies, int limit, int k, int curCookie)
{
if (idx == cookies.size()) return true;
if (curCookie == cookies.size()) return true;

int flag = 0;
for (int i=0; i<k; i++)
{
if (plan[i]+cookies[idx] > limit) continue;
if (plan[i]+cookies[curCookie] > limit) continue;
if (plan[i]==0)
{
if (flag==1) continue;
flag = 1;
}

plan[i] += cookies[idx];
if (dfs(cookies, limit, k, idx+1))
plan[i] += cookies[curCookie];
if (dfs(cookies, limit, k, curCookie+1))
return true;
plan[i] -= cookies[idx];
plan[i] -= cookies[curCookie];
}
return false;
}
Expand Down

0 comments on commit f9d6452

Please sign in to comment.