快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. /* 3509 */ #include <iostream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector&g…
Buge's Fibonacci Number Problem Description snowingsea is having Buge’s discrete mathematics lesson, Buge is now talking about the Fibonacci Number. As a bright student, snowingsea, of course, takes it as a piece of cake. He feels boring and soon com…
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * @ClassName: Fib * @Author: xiaof * @Description: 509. Fibonacci Number * The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibo…
HASH+暴力. /* 4403 */ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <map> using namespace std; #define MAXN 55 map<]; char s[MAXN]; int get(int b, int e) { ; for (int i=b; i<e; ++i)…
水题. #include <cstdio> #include <cstring> #include <cstdlib> int abs(int x) { ? -x:x; } int main() { int t, n; int cur, past; __int64 ans; bool flag; #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif scanf(&q…
[BZOJ4922][Lydsy六月月赛]Karp-de-Chant Number Description 卡常数被称为计算机算法竞赛之中最神奇的一类数字,主要特点集中于令人捉摸不透,有时候会让水平很高的选手迷之超时. 普遍认为卡常数是埃及人Qa'a及后人发现的常数.也可认为是卡普雷卡尔(Kaprekar)常数的别称.主要用于求解括号序列问题. 据考证,卡(Qa'a)是古埃及第一王朝的最后一位法老.他发现并研究了一种常数,后世以他的名字叫做卡常数.卡特兰数的起源也是因为卡的后人与特兰克斯结婚,生…
Difficulty:medium  More:[目录]LeetCode Java实现 Description Given an array nums containing n + 1 integers where each integer is between 1 and n(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numbe…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 二分查找 日期 题目地址:https://leetcode-cn.com/problems/check-if-a-number-is-majority-element-in-a-sorted-array/ 题目描述 Given an array nums sorted in non-decreasing order, and a number t…
题目描述 给出 $n$ 个括号序列,从中选出任意个并将它们按照任意顺序连接起来,求以这种方式得到匹配括号序列的最大长度. 输入 第一行包含一个正整数n(1<=n<=300),表示括号序列的个数. 接下来n行,每行一个长度在[1,300]之间的括号序列,仅由小括号构成. 输出 输出一行一个整数,即最大长度,注意你可以一个序列也不选,此时长度为0. 样例输入 3 ()) ((() )() 样例输出 10 题解 贪心+背包dp 首先对于一个括号序列,有用的只有:长度.消耗'('的数目.以及'('减去…
题目链接: http://acm.fzu.edu.cn/problem.php?pid=2238 题目大意: 已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类推,最终求A(m)的第i项mod1000000007 题目思路: [动态规划] 不难推出c[i][j]=c[i-1][j]+c[i][j-1] 但是i太大不能直接递推,m<=1000不能矩阵快速幂. 通过推导可以求出c[i][j]=a*C(n+m-1,n-1)+d*C(n+m-1,n-2) 求模时除…