前言 本文中的排列指由n个1, m个-1构成的序列中的一种. 题目这么长不吐槽了,但是这确实是一道好题. 题解 DP题话不多说,直接状态/变量/转移. 状态 我们定义f表示"最大prefix sum"之和 变量 f[i][j]为有i个1,j个-1的"最大prefix sum"之和 转移 我们记C[i][j]为\(\left(\begin{matrix} i \\ j\end{matrix}\right)\),那么: \[f[i][j] = \left\{\begin…
题目链接 思路分析 自认为是一道很好的构造题,但是我并不会做. 看了题解后有一些理解,在这里再梳理一遍巧妙的思路. 我们先来看这样的一张图: 我们发现当去掉叶子节点的父亲时,剩下树的价值和等于叶子节点的价值和,显然全是正的不太可能. 对于叶子节点我们不妨设他们的权值都是 \(1\) ,此时若删去最大的祖先节点,可以发现第二层节点的权值差正好和其儿子的个数差相同. 于是我们初步推断出权值大小可能和儿子的个数有着密切的关系.(实际就是这样) 上面的问题好像没有什么突破口了,我们转而考虑如何确定一个节…
Content 给定 \(t\) 组数据,每组数据给定一个数 \(n\),判断 \(n\) 是否能够分解成连续正整数和,能的话给出最小数最大的方案. 数据范围:\(1\leqslant n\leqslant 10^9\). Solution 这道题如果暴力枚举的话,看数据范围就知道肯定会爆炸.因此我们要考虑推式子. 首先,我们设分解后的数列长度为 \(k\),首项为 \(a_1\).那么显然得到 \(\text{(1)}\) 式: \(\begin{aligned}n&=\dfrac{(a_1+…
Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1ll * a[j] * C(k-+j-i,j-i)) % mod; } } 唯一注意的就是这个k会到1e9. 观察可能,其实我们最多也就用了n个组合数, 并且这个C(n, m) 的 m 足够小. 所以我们可以根据定义先把这几个组合数先预处理出来. 代码: #include<bits/stdc++.h>…
题面:P1466 集合 Subset Sums 题解: dpsum=N*(N+1)/2;模型转化为求选若干个数,填满sum/2的空间的方案数,就是背包啦显然如果sum%2!=0是没有答案的,就特判掉F[i][j]表示对于前i个数,和为j的方案数F[0][0]=1;F[i][j]+=F[i-1][j-i] (j>=i)转化为for(int i=1;i<=N;i++) for(int j=sum/2;j>=i;j--) F[j]+=F[j-i];答案是F[sum/2]/2,因为真实题目要求是…
Student Arseny likes to plan his life for n days ahead. He visits a canteen every day and he has already decided what he will order in each of the following n days. Prices in the canteen do not change and that means Arseny will spend ci rubles during…
大好的周末,决定写一篇读书笔记.:) 最近读了一些股票估值以及价值投资相关的文章和书籍.今天将其中的一本做一些笔记以及简单的总结. 该书名为<Complete Guide to Value Investing>,是 Doctor Wealth 公司出品的. 书籍目录结构 下面,我将重点章节进行简单总结. 概念及历史 本书前5章讲了价值投资的概念以及相关历史. 历史 下图,说明了价值投资主要理论的发展,以及相关几个大牛: 全是投资界大名鼎鼎的人物! 巴菲特的建议 其中,也说明了 Warren B…
Chinese author Lao Ma has a simple approach to his short stories: In the face of life, everything is funny. Mr. Lao, the pen name of Renmin University of China professor Ma Junjie, says there are plenty of laughable things in daily life that fuel his…
Lesson1  A puma at large Pumas are large, cat-like animals which are found in America. When reports came into London Zoo that a wild puma had been spotted forty-five miles south of London, they were not taken seriously. However, as the evidence began…
06:55:29 32w/m 45words. There was a time when the owners of shop and businesses in Chicago had to pay large sums of money to gangsters in return for 'protection'. If the money was not paid promptly, the gangsters would quickly put a man out of busine…