Skip to content

Commit 02b8313

Browse files
committed
1815 solved.
1 parent b836f83 commit 02b8313

File tree

1 file changed

+9
-5
lines changed
  • 1501-2000/1815-Maximum-Number-of-Groups-Getting-Fresh-Donuts/cpp-1815

1 file changed

+9
-5
lines changed

1501-2000/1815-Maximum-Number-of-Groups-Getting-Fresh-Donuts/cpp-1815/main.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Source : https://leetcode.com/problems/maximum-number-of-groups-getting-fresh-donuts/
22
/// Author : liuyubobobo
33
/// Time : 2020-06-11
4+
/// Updaetd: 2023-01-21
45

56
#include <iostream>
67
#include <vector>
@@ -10,7 +11,7 @@
1011
using namespace std;
1112

1213

13-
/// Memory Search - vector as key
14+
/// Memory Search
1415
/// Time Complexity: O(2^n)
1516
/// Space Complexity: O(2^n)
1617
class Solution {
@@ -23,15 +24,18 @@ class Solution {
2324
int res = f[0];
2425
f[0] = 0;
2526

26-
map<vector<int>, int> dp;
27+
map<long long, int> dp;
2728
res += dfs(f, batchSize, dp);
2829
return res;
2930
}
3031

3132
private:
32-
int dfs(vector<int>& f, int k, map<vector<int>, int>& dp){
33+
int dfs(vector<int>& f, int k, map<long long, int>& dp){
3334

34-
auto iter = dp.find(f);
35+
long long h = 0;
36+
for(int e: f) h = h * 10ll + e;
37+
38+
auto iter = dp.find(h);
3539
if(iter != dp.end()) return iter->second;
3640

3741
int pre = f[0];
@@ -44,7 +48,7 @@ class Solution {
4448
f[0] = pre;
4549
f[i] ++;
4650
}
47-
return dp[f] = res;
51+
return dp[h] = res;
4852
}
4953
};
5054

0 commit comments

Comments
 (0)