网站首页 站内搜索

搜索结果

查询Tags标签: pairs,共有 29条记录
  • ABC263 G - Erasing Prime Pairs

    拆点 + 最大流 G - Erasing Prime Pairs (atcoder.jp) 题意 有 n(n <= 100)种互不相同的数,分别是 \(A[i]\) (<=1e7), 每个有 \(B[i]\) 个 每次可以任意取两个数,如果相加是素数就消去这两个数,求最多操作次数 思路 思路一、不考虑 1 + 1 = 2 出现偶素数,可…

    2022/9/8 23:53:09 人评论 次浏览
  • [LC646]最长数对链

    题目概述 给出 n 个数对。 在每一个数对中,第一个数字总是比第二个数字小。 现在,我们定义一种跟随关系,当且仅当 b < c 时,数对(c, d) 才可以跟在 (a, b) 后面。我们用这种形式来构造一个数对链。 给定一个数对集合,找出能够形成的最长数对链的长度。你不需要用到…

    2022/9/3 23:26:29 人评论 次浏览
  • 1202. 交换字符串中的元素(并查集)

    1202. 交换字符串中的元素给你一个字符串 s,以及该字符串中的一些「索引对」数组 pairs,其中 pairs[i] = [a, b] 表示字符串中的两个索引(编号从 0 开始)。 你可以 任意多次交换 在 pairs 中任意一对索引处的字符。 返回在经过若干次交换后,s 可以变成的按字典序最小…

    2022/5/5 6:13:13 人评论 次浏览
  • Leetcode 24. 两两交换链表中的节点 Swap Nodes in Pairs - Python

    # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution:def swapPairs(self, head: ListNode) -> ListNode:sentinalNode = ListNode(next=head)…

    2022/2/24 17:22:33 人评论 次浏览
  • 20.有效括号

    public:bool isValid(string s) {unordered_map<char,char> pairs={{ ),(},{],[},{},{}};stack<char> stk;for(char ch: s){if(pairs.count(ch)){if(stk.empty()||stk.top()!=pairs[ch])return false;else stk.pop();}else stk.push(ch);}if(stk.empty())retu…

    2022/2/17 23:14:52 人评论 次浏览
  • 力扣 括号生成 Python

    这个题用动态规划的思路来做。初始化一个一维列表来记录 括号对数 <= n 的所有状态,如 dp[3] 包含括号对数为3的所有序列。只要保证从第一个状态是正确的序列,设计好状态转移,就可以保证后续得到的所有括号序列都是正确的 初始条件:dp[0] = [""] 状态转移…

    2022/2/6 17:12:30 人评论 次浏览
  • 为了转行程序员而努力的第三十天-栈

    今天又去看了演出,又去聚了餐,还录了声音,也听了网课刷了题,总的来说是比较充实的一天,除了晚上记录的时间剩下比较少。今天刷了两道栈有关的题,感觉其实栈没有链表实现复杂。 今日进度: 1.录了小王子,还录了谚语和英语 2.坚持听网课,刷题 3.坚持锻炼 学习笔记:…

    2022/1/23 1:05:16 人评论 次浏览
  • [CodeForces] Dirty Deeds Done Dirt Cheap

    ProblemFirst I thought about modelling this problem as a directed graph, where between each pair of nodes, an edge represents a valid < > or > < transition. Then do a dfs with dp to compute the longest valid path. But there can be as many …

    2022/1/20 6:43:11 人评论 次浏览
  • [CodeForces] Dirty Deeds Done Dirt Cheap

    ProblemFirst I thought about modelling this problem as a directed graph, where between each pair of nodes, an edge represents a valid < > or > < transition. Then do a dfs with dp to compute the longest valid path. But there can be as many …

    2022/1/20 6:43:11 人评论 次浏览
  • [算法][排列组合]每一轮两两组合不允许重复

    1.问题描述: 给定N个数(N是偶数),给它们进行两两组合并列举所有可能的轮数,每一轮的组合不可以一样,并且两个元素只允许组合一次。 比如N是4,有A,B,C,D共4个元素,那么可以共有3轮组合,分别是: 第一轮第二轮第三轮A-B,C-DA-C,B-DA-D,B-C 从第四轮开始要开始重复了…

    2022/1/12 22:07:33 人评论 次浏览
  • [算法][排列组合]每一轮两两组合不允许重复

    1.问题描述: 给定N个数(N是偶数),给它们进行两两组合并列举所有可能的轮数,每一轮的组合不可以一样,并且两个元素只允许组合一次。 比如N是4,有A,B,C,D共4个元素,那么可以共有3轮组合,分别是: 第一轮第二轮第三轮A-B,C-DA-C,B-DA-D,B-C 从第四轮开始要开始重复了…

    2022/1/12 22:07:33 人评论 次浏览
  • 【leetcode】1010. Pairs of Songs With Total Durations Divisible by 60

    You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with …

    2022/1/3 6:12:53 人评论 次浏览
  • 【leetcode】1010. Pairs of Songs With Total Durations Divisible by 60

    You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with …

    2022/1/3 6:12:53 人评论 次浏览
  • LeetCode_Heap_373. Find K Pairs with Smallest Sums 查找和最小的K对数字 【堆】【C++/java】【中等】

    目录 一,题目描述 英文描述 中文描述 示例与说明 二,解题思路 三,AC代码 C++ Java 四,解题过程 第一博 第二搏 第三博一,题目描述 英文描述You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u, v) whi…

    2021/11/7 11:40:24 人评论 次浏览
  • LeetCode_Heap_373. Find K Pairs with Smallest Sums 查找和最小的K对数字 【堆】【C++/java】【中等】

    目录 一,题目描述 英文描述 中文描述 示例与说明 二,解题思路 三,AC代码 C++ Java 四,解题过程 第一博 第二搏 第三博一,题目描述 英文描述You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define a pair (u, v) whi…

    2021/11/7 11:40:24 人评论 次浏览
共29记录«上一页12下一页»
扫一扫关注最新编程教程