Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n).   Input The input consists of multiple test cases. Each test case contains…
题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直到无糖果剩余为止.给出数字n,问有多少种分发糖果的方法. 样例输入 复制 1 4 样例输出 复制 8 解题思路:我们可以这样想,一个糖果的话,应该是只有1种方法记为x1,如果是两个糖果的话,有两种方法即为x2,分别为(1,1)和(2),从中我们可以想到如果n个糖果的话,就可以分为第n个人取1个的话就有x(…
In a galaxy far far away there is an ancient game played among the planets. The specialty of the gameis that there is no limitation on the number of players in each team, as long as there is a captain inthe team. (The game is totally strategic, so so…
1575: Gingers and Mints Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lldSubmitted: 24  Accepted: 13[Submit][Status][Web Board] Description fcbruce owns a farmland, the farmland has n * m grids. Some of the grids are stones, rich soil i…
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1008 题意概括 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱. 题解 水题一道. 我们考虑发生越狱的是总数-不发生越狱的. 总数很好算:就是mn 但是不发生的同样也很好算. 第一个位置,有m中选择,后面每一个位置都要和前面一个不一样,那么有m-1种选择. 所以是m*(m-…
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous. Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 3 c…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5015 看到这个限时,我就知道这题不简单~~矩阵快速幂,找递推关系 我们假设第一列为: 23 a1 a2 a3 a4 则第二列为: 23*10+3 23*10+3+a1 23*10+3+a1+a2 23*10+3+a1+a2+a3 23*10+3+a1+a2+a3+a4 进一步转化可以得到: 代码: #include <iostream> #include <string.h> usin…
正解:矩阵快速幂/tarjan+倍增 解题报告: 传送门! 跟着神仙做神仙题系列III 这题首先一看到就会想到快速幂趴?就会jio得,哦也不是很难哦 然而,看下数据范围,,,1×105,,,显然开不下TT 所以考虑优化快速幂(或找环+倍增 两种方法都港下趴 先说图论好辣QwQ 大概是这样的: 首先我们把每个座位都抽象成一个点,由它给我的A[]可以知道坐在每个座位上的人会移到哪儿 我们就可以理解为连了一条边 显然的是我们可以换了很多次之后换回来,于是就成了一个环了 然后我们就求一波强连通分量,这样…
根据 高中的数学知识 即可推出 ans=m^n-m*(m-1)^(n-1) .快速幂取模搞一下即可. #include<cstdio> using namespace std; typedef long long ll; #define MOD 100003 ll n,m; ll Quick_Pow(ll x,ll p) { ; ll ans=Quick_Pow(x,p>>); ans=ans*ans%MOD; ) ans=ans*x%MOD; return ans; } int…
$A(x)=1+x^2/2!+x^4/4!...$ $A(x)=1+x^1/1!+x^2/2!...$ 然后把生成函数弄出来. 暴力手算. 发现结论. 直接是$4^{n-1}+2^{n-1}$ 然后快速幂. #include <map> #include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include…