随笔分类 -  Algorithm

1 2 3 4 5 ··· 10 下一页
摘要:Problem Link: https://atcoder.jp/contests/abc404/tasks/abc404_e Greedy For position i, if there exists a postion j in [i - C[i], i - 1], where A[j] > 阅读全文
posted @ 2025-05-04 11:24 Review->Improve 阅读(60) 评论(0) 推荐(0)
摘要:Problem Link If we pick A[i] the 2nd time, it means we have a cycle. Proof: 1st time we pick A[i], the sum before adding A[i] is x; 2nd time we pick A 阅读全文
posted @ 2024-08-16 08:05 Review->Improve 阅读(32) 评论(0) 推荐(0)
摘要:Problem Link Based on initial observation, it seems that greedily pick the smallest row / column length works. But the last example test case outputs 阅读全文
posted @ 2024-08-14 23:46 Review->Improve 阅读(82) 评论(0) 推荐(0)
摘要:1. The 1st palindromic number is 0, so we do N-- to exclude 0. 2. F(k): the number of palindromic numbers of length k. F(1) = 9; F(2) = 9; F(k) = F(k 阅读全文
posted @ 2024-07-22 02:21 Review->Improve 阅读(46) 评论(0) 推荐(0)
摘要:You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defin 阅读全文
posted @ 2024-05-14 23:37 Review->Improve 阅读(45) 评论(0) 推荐(0)
摘要:Incorrect solution: greedily find out how many consecutive S we can convert to all o. Then for the remaining replace operations, try each starting pos 阅读全文
posted @ 2023-09-14 05:13 Review->Improve 阅读(20) 评论(0) 推荐(0)
摘要:Problem Statment Assume the first N - 1 rounds have been played and we are left with a %7 value R. There are 2 cases depending on who plays the last r 阅读全文
posted @ 2023-09-11 06:47 Review->Improve 阅读(30) 评论(0) 推荐(0)
摘要:Problem Statement If we add edges between every pair of sets that have shared elements, there will be O(N^2) edges to traverse. Instead, we can add N 阅读全文
posted @ 2023-07-17 10:54 Review->Improve 阅读(56) 评论(0) 推荐(0)
摘要:The key observation is that there is always at most 1 cell that violates both conditions. Proof: if x violates both conditions, that means all other n 阅读全文
posted @ 2023-03-21 23:37 Review->Improve 阅读(33) 评论(0) 推荐(0)
摘要:You are given an undirected graph (the "original graph") with n nodes labeled from 0 to n - 1. You decide to subdivide each edge in the graph into a c 阅读全文
posted @ 2023-02-21 07:33 Review->Improve 阅读(41) 评论(0) 推荐(0)
摘要:Problem Statement dp[i][j]: the number of subsets of A[0, i] whose sum is j. dp[0][0] = 1, there is only 1 way of not picking anything from an empty a 阅读全文
posted @ 2023-02-21 01:13 Review->Improve 阅读(35) 评论(0) 推荐(0)
摘要:You are given a 2D integer array, queries. For each queries[i], where queries[i] = [ni, ki], find the number of different ways you can place positive 阅读全文
posted @ 2023-01-06 07:22 Review->Improve 阅读(39) 评论(0) 推荐(0)
摘要:Problem Statement 1. N is up to 35, so trying all possible subsequences is too slow (2^35). We can apply the meet in the middle technique and divide A 阅读全文
posted @ 2022-09-30 10:48 Review->Improve 阅读(43) 评论(0) 推荐(0)
摘要:You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (in 阅读全文
posted @ 2022-03-30 00:50 Review->Improve 阅读(138) 评论(0) 推荐(0)
摘要:There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from t 阅读全文
posted @ 2022-03-16 22:38 Review->Improve 阅读(85) 评论(0) 推荐(0)
摘要:Problem Link Dp[i][j]: the number of possible ways from s[0, i] with the ith statement ending with indentation j. dp[0][0] = 1, the 1st statement must 阅读全文
posted @ 2022-02-07 23:04 Review->Improve 阅读(81) 评论(0) 推荐(0)
摘要:A. Counting Kangaroos is Fun There can be only at most N / 2 hold and held pairs based the problem's statment. So a greedy approach is just to divide 阅读全文
posted @ 2022-01-24 12:52 Review->Improve 阅读(105) 评论(0) 推荐(0)
摘要:Problem First I thought about modelling this problem as a directed graph, where between each pair of nodes, an edge represents a valid < > or > < tran 阅读全文
posted @ 2022-01-20 01:05 Review->Improve 阅读(78) 评论(0) 推荐(0)
摘要:Problem S: the set of numbers said by player 1; P: the set of numbers said by player 2; S^2 * P = a; S * P^2 = b; a * b = (S * P)^3, so a * b must be 阅读全文
posted @ 2022-01-18 06:35 Review->Improve 阅读(27) 评论(0) 推荐(0)
摘要:Problem Each fence is increased at most 2 times, so dp[i][j] is the min cost to make A[0, i] great with the last fence A[i] increased j times. The ans 阅读全文
posted @ 2022-01-18 03:22 Review->Improve 阅读(48) 评论(0) 推荐(0)

1 2 3 4 5 ··· 10 下一页