-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deleted: Dijkstra.java new file: a.txt new file: b.txt new file: bytedance/拨号器.py new file: bytedance/最优硬币组合问题.py new file: bytedance/最大乘积问题.py new file: bytedance/股票价格上涨天数计算.py new file: bytedance/连续子串和的整除问题.py new file: bytedance/非重叠子数组的最大和.py new file: draft.cpp new file: draft.exe modified: test.cpp modified: test.exe modified: test.py deleted: test2.cpp
- Loading branch information
1 parent
4af8a89
commit 8ac5cd1
Showing
16 changed files
with
330 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SJTU AI4EDA课题组招收科研助理2-3名,提供科研酬金5000-8000每月(可远程,来交大可以提供房补),欢迎相关背景或者感兴趣的本科生、研究生参与到课题组的开源项目中来!一方面为国内开源EDA做一份小小的贡献,另一方面接触与工业界紧密结合的EDA/RL/GCN等领域的前沿科研。导师刚从国外回国,与工业界合作紧密,课题组氛围良好,详情见导师主页:https://me.sjtu.edu.cn/en/FullTimeTeacher/shaoleilai.html。感兴趣的同学,请将自己的简历(成绩单如果有)发送到[email protected], 邮件标题:姓名-科研助理申请-感兴趣的科研方向(例如: Larry-科研助理申请-VLSI/EDA)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SJTU AI4EDA课题组招收科研助理2-3名,提供科研酬金5000-8000每月(可远程,来交大可以提供房补),欢迎相关背景或者感兴趣的本科生、研究生参与到课题组的开源项目中来!一方面为国内开源EDA做一份小小的贡献,另一方面接触与工业界紧密结合的EDA/RL/GCN等领域的前沿科研。导师刚从国外回国,与工业界合作紧密,课题组氛围良好!感兴趣的同学,请将自己的简历(成绩单如果有)发送到[email protected], 邮件标题:姓名-科研助理申请-感兴趣的科研方向(例如: Larry-科研助理申请-VLSI/EDA)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 题解:https://bytedance.larkoffice.com/docx/FBj5dyLwZof6alxsvTvcCmWzn6g | ||
def solution(n: int) -> int: | ||
d = { | ||
0: [4, 6], | ||
1: [6, 8], | ||
2: [7, 9], | ||
3: [4, 8], | ||
4: [0, 3, 9], | ||
5: [], | ||
6: [0, 1, 7], | ||
7: [2, 6], | ||
8: [1, 3], | ||
9: [2, 4] | ||
} | ||
''' | ||
dp数组是二维的写法 | ||
dp[i][j]表示已经按下i个数字且最后一个数字是j的号码数量 | ||
# 创建一个二维数组,第一维大小是n,第二维大小是10 | ||
dp = [[0] * 10 for _ in range(n + 1)] | ||
for i in range(10): | ||
dp[1][i] = 1 | ||
for i in range(2, n + 1): | ||
for j in range(10): | ||
for k in d[j]: | ||
dp[i][j] += dp[i - 1][k] # dp[i][j]一开始是0,然后加上dp[i - 1][k]的值 | ||
return sum(dp[n]) % 1000000007 | ||
''' | ||
dp = [1] * 10 | ||
for _ in range(2, n + 1): | ||
t = [0] * 10 | ||
for j in range(10): | ||
for k in d[j]: | ||
t[j] += dp[k] | ||
dp = t | ||
return sum(dp) % 1000000007 | ||
|
||
if __name__ == '__main__': | ||
print(solution(1) == 10) | ||
print(solution(2) == 20) | ||
print(solution(3) == 46) | ||
print(solution(4) == 104) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
def solution(array, total): | ||
dp = [0] * (total + 1) | ||
|
||
for i in range(len(array)): | ||
|
||
|
||
if __name__ == "__main__": | ||
# Add your test cases here | ||
|
||
print(solution([1, 2, 5], 18) == [5, 5, 5, 2, 1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 题解:https://bytedance.larkoffice.com/docx/JNzgdNYITosd7oxvIqWcWcWnn8g | ||
def solution(n, array): | ||
left, right = [0] * n, [0] * n | ||
stk = [] | ||
for i in range(n): | ||
while stk and array[stk[-1]] <= array[i]: | ||
t = stk.pop() | ||
if (array[t] < array[i]): | ||
right[t] = i + 1 # 单调栈,如果当前元素比栈顶元素大,则栈顶元素的右边第一个比它大的元素就是当前元素(加1是题目需要),掌握这个技巧,就可以在一次遍历中同时找到左右两边第一个比当前元素大的元素,而不需要两次遍历。 | ||
if stk: | ||
left[i] = stk[-1] + 1 # 单调栈,找到左边第一个比当前元素大的元素(加1是题目需要) | ||
stk.append(i) | ||
return max(left[i] * right[i] for i in range(n)) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Add your test cases here | ||
|
||
print(solution(5, [5, 4, 3, 4, 5]) == 8) | ||
# left = [0, 1, 2, 1, 0] right = [0, 5, 4, 5, 0] | ||
print(solution(6, [2, 1, 4, 3, 6, 5]) == 15) | ||
print(solution(7, [1, 2, 3, 4, 5, 6, 7]) == 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 题解:https://bytedance.larkoffice.com/docx/ZjixdJfDkoTT68xSVSScxf3tnP7 | ||
def solution(N, stockPrices): | ||
ans = [0] * N | ||
st = [] | ||
for i, v in enumerate(stockPrices): | ||
while st and stockPrices[st[-1]] < v: | ||
idx = st.pop() # 对于此时栈顶的元素arr[st[-1]],如果arr[st[-1]] < arr[i],则说明arr[i]是其第一个在arr[st[-1]]右边且比arr[st[-1]]大的元素 | ||
ans[idx] = i - idx | ||
st.append(i) | ||
return ans | ||
|
||
if __name__ == '__main__': | ||
print(solution(5, [33, 34, 14, 12, 16]) == [1, 0, 2, 1, 0]) | ||
print(solution(6, [45, 44, 46, 43, 42, 48]) == [2, 1, 3, 2, 1, 0]) | ||
print(solution(3, [10, 9, 8]) == [0, 0, 0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
''' | ||
余数:如果两个前缀和的余数相同,那么它们之间的子串和一定可以被 b 整除。 | ||
解释:s1 = k1 * b + r, s2 = k2 * b + r, s2 - s1 = (k2 - k1) * b,即 s2 和 s1 之间的子串和一定可以被 b 整除。 | ||
''' | ||
def solution(n, b, sequence): | ||
prefix_sum = [0] * (n + 1) | ||
for i in range(1, n + 1): | ||
prefix_sum[i] = prefix_sum[i - 1] + sequence[i - 1] | ||
|
||
print(prefix_sum) | ||
remainder_count = {} | ||
ans = 0 | ||
|
||
for i in range(n + 1): # 对于前0个元素的前缀和的余数为0,这个也要统计。如果s[i] % b == 0,那么a[0]~a[i - 1]的子串是符合条件的。 | ||
remainder = prefix_sum[i] % b | ||
if remainder in remainder_count: | ||
ans += remainder_count[remainder] # s[i]与remainder_count[remainder]之间的子串和都可以被b整除,ans加上它们的个数 | ||
remainder_count[remainder] += 1 # 更新remainder_count[remainder]的值 | ||
else: | ||
remainder_count[remainder] = 1 # 如果remainder不在remainder_count中,那么就加入remainder_count中 | ||
|
||
return ans | ||
|
||
if __name__ == "__main__": | ||
# You can add more test cases here | ||
print(solution(3, 3, [1, 2, 3]) == 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# 题解:https://bytedance.larkoffice.com/docx/EkpkdhVD4o23G4xJ70IcuFJcnTf | ||
def solution(nums: list, firstLen: int, secondLen: int) -> int: | ||
def sum_subarray(nums, length): | ||
nums_sum = [0] * len(nums) | ||
current_sum = sum(nums[:length]) | ||
nums_sum[length - 1] = current_sum | ||
for i in range(length, len(nums)): | ||
current_sum += nums[i] - nums[i - length] | ||
nums_sum[i] = current_sum | ||
return nums_sum | ||
def max_sum_subarray(arr, length): | ||
max_sum = [0] * len(arr) | ||
max_sum[length - 1] = arr[length - 1] | ||
for i in range(length, len(arr)): | ||
max_sum[i] = max(max_sum[i - 1], arr[i]) | ||
return max_sum | ||
sumfirst = sum_subarray(nums, firstLen) | ||
sumsecond = sum_subarray(nums, secondLen) | ||
maxfirstleft = max_sum_subarray(sumfirst, firstLen) | ||
maxfirstright = max_sum_subarray(sumfirst[::-1], 1)[::-1] | ||
|
||
ans = 0 | ||
for i in range(secondLen - 1, len(nums)): | ||
before = maxfirstleft[i - secondLen] if i - secondLen >= 0 else 0 | ||
after = maxfirstright[i + firstLen] if i + firstLen < len(nums) else 0 | ||
ans = max(ans, sumsecond[i] + max(before, after)) | ||
|
||
return ans | ||
|
||
|
||
if __name__ == "__main__": | ||
print(solution(nums=[0, 6, 5, 2, 2, 5, 1, 9, 4], firstLen=1, secondLen=2) == 20) | ||
print(solution(nums=[3, 8, 1, 3, 5, 2, 1, 0], firstLen=3, secondLen=2) == 21) | ||
print(solution(nums=[2, 1, 4, 3, 5, 9, 5, 0, 3, 8], firstLen=4, secondLen=3) == 33) | ||
print(solution(nums=[14, 8, 3, 9, 1, 9, 5, 11, 17, 4, 9, 16, 15, 13], firstLen=1, secondLen=12) == 126) | ||
''' | ||
def solution(nums: list, firstLen: int, secondLen: int) -> int: | ||
maxfirstleft = [0] * len(nums) | ||
maxfirstright = [0] * len(nums) | ||
sumfirst, sumsecond = [0] * len(nums), [0] * len(nums) | ||
left, right = 0, 0 | ||
while left <= len(nums) - firstLen: | ||
sumfirst[left] += nums[right] | ||
right += 1 | ||
if right - left == firstLen: | ||
maxfirstleft[left] = max(maxfirstleft[left - 1] if left > 0 else -2e9, sumfirst[left]) | ||
left += 1 | ||
if left < len(nums): | ||
sumfirst[left] = sumfirst[left - 1] - nums[left - 1] | ||
for i in range(len(nums) - firstLen, -1, -1): | ||
maxfirstright[i] = max(maxfirstright[i + 1] if i < len(nums) - firstLen else -2e9, sumfirst[i]) | ||
left, right = 0, 0 | ||
while left <= len(nums) - secondLen: | ||
sumsecond[left] += nums[right] | ||
right += 1 | ||
if right - left == secondLen: | ||
left += 1 | ||
if left < len(nums): | ||
sumsecond[left] = sumsecond[left - 1] - nums[left - 1] | ||
ans = -2e9 | ||
for i in range(0, len(nums) - secondLen + 1): | ||
before = maxfirstleft[i - firstLen] if i - firstLen >= 0 else 0 | ||
after = maxfirstright[i + secondLen] if i + secondLen < len(nums) else 0 | ||
ans = max(ans, sumsecond[i] + max(before, after)) | ||
# print(before, after, sumsecond[i], ans) | ||
# print(sumfirst, sumsecond, maxfirstleft, ans) | ||
return ans | ||
if __name__ == "__main__": | ||
# print(solution(nums=[0, 6, 5, 2, 2, 5, 1, 9, 4], firstLen=1, secondLen=2) == 20) | ||
# print(solution(nums=[3, 8, 1, 3, 5, 2, 1, 0], firstLen=3, secondLen=2) == 21) | ||
# print(solution(nums=[2, 1, 4, 3, 5, 9, 5, 0, 3, 8], firstLen=4, secondLen=3) == 33) | ||
print(solution(nums=[14, 8, 3, 9, 1, 9, 5, 11, 17, 4, 9, 16, 15, 13], firstLen=1, secondLen=12) == 126) | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// to_string() map[]注意访问无效ans diff[]change[] | ||
// dfs 重复则终结 | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
map<string, bool> mp; | ||
int k, ans; | ||
int diff[20], change[20]; | ||
string s; | ||
void dfs(string s1) | ||
{ | ||
if (mp[s1]) | ||
return; // 已经存在该字符串无需重复替换规则 | ||
mp[s1] = 1; | ||
ans++; | ||
for (int i = 1; i <= k; i++) | ||
{ | ||
for (int j = 0; j < s1.length(); j++) | ||
{ | ||
if (s1[j] == diff[i]) | ||
{ | ||
string s2 = s1.substr(0, j) + to_string(change[i]) + s1.substr(j + 1); | ||
dfs(s2); | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
int main() | ||
{ | ||
cin >> s >> k; | ||
for (int i = 1; i <= k; i++) | ||
{ | ||
cin >> diff[i] >> change[i]; | ||
} | ||
dfs(s); | ||
cout << ans << endl; | ||
return 0; | ||
} |
Oops, something went wrong.