2021/8/23
两题困难
[//]: # (支持粘贴图片啦🎉🎉🎉) [//]: # (保存的笔记可以在小程序中查看) ``` class Solution { public: int dp[10]; int vis[10]; string ans = ""; void dfs(int n,int k,int id){ int sum = 0; for(int i = 1; i <= n; ++ i){ if(vis[i] == 0){ if(id == n){ ans += i + '0'; return ; } sum += dp[n - id]; } if(sum >= k){ ans += i + '0'; sum -= dp[n - id]; vis[i] = 1; dfs(n,k - sum,id + 1); return ; } } } string getPermutation(int n, int k) { dp[1] = 1; for(int i = 2; i <= 9; ++ i){ dp[i] = dp[i - 1] * i; } dfs(n,k,1); return ans; } }; ``` [//]: # (支持粘贴图片啦🎉🎉🎉) [//]: # (保存的笔记可以在小程序中查看) ``` 二分 class Solution { public: int splitArray(vector<int>& nums, int m) { int l = 0,r = 1e9 + 7; int ans = 1e9+7; while(l <= r){ int cnt = 0; int mid = (l + r) >> 1; int t = 0; for(int i = 0,sum = 0; i <= nums.size() && cnt <= m; ++ i){ if(i == nums.size()){ ++ cnt; t = max(sum,t); continue; } if(sum + nums[i] <= mid){ sum += nums[i]; } else { ++ cnt; t = max(sum,t); sum = 0; -- i; } } if(cnt <= m){ ans = min(ans,t); r = mid - 1; } else l = mid + 1; } return ans; } }; ```
mysql 3讲
两场笔试
学习了第七章