随笔分类 -  动态规划

摘要:题目:戳这里 题意:给一个不下降序列,有n个数。问能否构造一个二叉搜索树,满足父亲和儿子之间的gcd>1. 解题思路:其实这题就是构造个二叉搜索树,只不过多了个条件。主要得了解二叉搜索树的性质,比如一段区间[l,r],这段区间要么是[l-1]的右子树,要么是[r+1]的左子树。(二叉树中左子树都比根 阅读全文
posted @ 2018-11-08 16:32 euzmin 阅读(150) 评论(0) 推荐(0)
摘要:学习博客:戳这里 附本人代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e5 + 10; 5 const ll mod = 998244353; 6 s 阅读全文
posted @ 2018-11-03 12:06 euzmin 阅读(408) 评论(0) 推荐(0)
摘要:学习博客:戳这里 阅读全文
posted @ 2018-10-09 15:24 euzmin 阅读(132) 评论(0) 推荐(0)
摘要:题目:戳这里 题意:一个数字n不断迭代地除以自身的因子得到1。求这个过程中操作除法次数的期望。 解题思路: 求概率基本都是从一个最基础的状态开始延伸推出公式,得出答案。因为每个数都有个共同的最终状态1,所以我们从1向n推(注意用到期望的可加性,可加性不需要事件相互独立。可以推出期望公式:E=1/n 阅读全文
posted @ 2018-09-30 22:12 euzmin 阅读(226) 评论(0) 推荐(0)
摘要:学习博客: 戳这里 戳这里 “在信息学竞赛中,有这样一类问题:求给定区间中,满足给定条件的某个D 进制数或此类数的数量。所求的限定条件往往与数位有关,例如数位之和、指定数码个数、数的大小顺序分组等等。题目给定的区间往往很大,无法采用朴素的方法求解。此时,我们就需要利用数位的性质,设计log(n)级别 阅读全文
posted @ 2018-08-07 17:50 euzmin 阅读(176) 评论(0) 推荐(0)
摘要:题目链接:戳这里 转自:戳这里 题意:长度为n的序列,删掉m个数字后有多少种不同的序列。n<=10^5,m<=10。 题解:dp[i][j]表示加入第i个数字后,总共删掉j个数字时,有多少种不同的序列。假设不考虑有重复的情况,dp方程为:dp[i][j]=dp[i-1][j] (第i个数字不删)+d 阅读全文
posted @ 2018-07-24 09:17 euzmin 阅读(231) 评论(0) 推荐(0)
摘要:题目链接:戳这里 题意:有A只蚂蚁,来自T个家族,每个家族有ti只蚂蚁。任取n只蚂蚁(S <= n <= B),求能组成几种集合? 这道题可以用dp或母函数求。 多重集组合数也是由多重背包问题拓展出来的一类经典问题,而此类问题也都可以用母函数求. 给大家讲2种方法: ①朴素方法: 状态:dp[i][ 阅读全文
posted @ 2018-07-18 22:58 euzmin 阅读(289) 评论(0) 推荐(0)
摘要:这段时间刷dp,总结出了一个不算套路的套路。 1.根据题意确定是否有重叠子问题,也就是前面的状态对后面的有影响,基本满足这个条件的就可以考虑用dp了。 2.确定是dp后,就是最难的部分——如何根据题意选定正确的状态,比如dp[i][j]表示前i个物品价格为j的所有可能。(这个需要刷题积累经验,暂时还 阅读全文
posted @ 2018-07-18 22:35 euzmin 阅读(165) 评论(0) 推荐(0)
摘要:Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID 阅读全文
posted @ 2018-07-18 16:21 euzmin 阅读(129) 评论(0) 推荐(0)
摘要:People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box and found there were some co 阅读全文
posted @ 2018-07-18 15:17 euzmin 阅读(194) 评论(0) 推荐(0)
摘要:非常详细的题解:戳这里 例题:poj-3783 Balls Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1151 Accepted: 748 Description The classic Two Glass Ba 阅读全文
posted @ 2018-05-10 21:17 euzmin 阅读(494) 评论(0) 推荐(0)
摘要:链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网 Now HUST got a big land whose capacity is C to plant trees. We have n trees which could be plant i 阅读全文
posted @ 2018-05-06 12:33 euzmin 阅读(446) 评论(0) 推荐(0)
摘要:入口:戳这里 阅读全文
posted @ 2018-04-12 17:15 euzmin 阅读(120) 评论(0) 推荐(0)
摘要:If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number. You are required to count the n 阅读全文
posted @ 2018-04-12 17:13 euzmin 阅读(242) 评论(0) 推荐(0)
摘要:D. Two Paths time limit per test 2 seconds time limit per test memory limit per test 64 megabytes memory limit per test input standard input input out 阅读全文
posted @ 2018-03-02 15:34 euzmin 阅读(210) 评论(0) 推荐(0)
摘要:题目大意 给定一个含有N个数的序列,要求你对一些数减掉或者加上某个值,使得序列变为非递减的,问你加减的值的总和最少是多少? 题解 一个很显然的结果就是,变化后的每一个值肯定是等于原来序列的某个值,因为只需要变为非递减的,所以对于某个数要么不变,要么变成左右附件的某个值。这样我们就可以根据前述条件得出 阅读全文
posted @ 2018-02-25 21:49 euzmin 阅读(212) 评论(0) 推荐(0)
摘要:太难了,学不会。看了两天都会背了,但是感觉题目稍微变下就不会了。dp还是摸不到路子。 附ac代码: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 阅读全文
posted @ 2018-02-03 14:45 euzmin 阅读(279) 评论(0) 推荐(0)
摘要:求出LCIS并输出其路径。 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <fstream> 6 #include <algorithm> 7 #includ 阅读全文
posted @ 2018-02-01 18:25 euzmin 阅读(302) 评论(0) 推荐(0)
摘要:D. How many trees? time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output D. How many trees? time 阅读全文
posted @ 2018-01-31 09:16 euzmin 阅读(196) 评论(0) 推荐(0)
摘要:C. Looking for Order time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Girl Lena likes it 阅读全文
posted @ 2018-01-30 17:08 euzmin 阅读(251) 评论(0) 推荐(0)