任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 4043    Accepted Submission(s): 1560 Problem Description There a…
There are nn apples on a tree, numbered from 11 to nn. Count the number of ways to pick at most mm apples.  Input The first line of the input contains an integer TT (1≤T≤105)(1≤T≤105) denoting the number of test cases. Each test case consists of one…
hdu6333 Problem B. Harvest of Apples 题目传送门 题意: 求(0,n)~(m,n)组合数之和 题解: C(n,m)=C(n-1,m-1)+C(n-1,m)    设 S(n,m)=C(n,0)+C(n,1)+C(n,2)+...+C(n,m) 然后将S(n,m) 通过 第一个公式 拆项 最后化简 变为 S(n,m)=2*S(n-1,m)-C(n-1,m); 即: 所以可以离线用莫队算法 参考博客:链接1.链接2 代码: #include <bits/stdc+…
Problem B. Harvest of Apples Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description There are n apples on a tree, numbered to n. Count the number of ways to pick at most m apple…
HDU-6333 题意: 有n个不同的苹果,你最多可以拿m个,问有多少种取法,多组数据,组数和n,m都是1e5,所以打表也打不了. 思路: 这道题要用到组合数的性质,记S(n,m)为从n中最多取m个的方法总数,显然是C(n,0),C(n,1)……C(n,m)的和. 显然S(n,m+1) = S(n, m) + C(n,m+1); 还有一个等式就不那么明显了,S(n+1,m) = 2 * S(n,m) - C(n,m); 我也是在王神犇的指导下明白的. 既然知道了一组(n,m)是可以在很快的时间下…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6333 解题心得: 这个题可以说是十分精彩了,首先推组合数学的公式,其中一个很重要的公式是Cnm = Cmn-1 + Cm-1n-1  这个公式知道杨辉三角的都明白,但是一看发现似乎没啥用.但是可以以这个公式为基础继续推演下去. 设Snm = Cn1 + Cn2 + Cn3 + ...... Cnm 然后继续使用上面的基本公式可以化成 Sn m-1 = Sn m - Cn m Sn m+1 = Sn…
题意: 给定T组询问,每组有两个数字n和m,求sigma i=0..m c(n,i) 答案对1e9+7取模 T<=1e5 1<=n,m<=1e5 思路: 注意要先变n再变m,否则会因n太小有些组合数会丢失 关键点在于n的转移,m的转移谁都会 预处理数组越界要小心 #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<iostream&g…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题目: 题意:求C(n,0)+C(n,1)+……+C(n,m)的值. 思路:由于t和n数值范围太大,所以此题查询复杂度不能太高,由组合数的将前k项求和可以推出,从而可以转换成莫队的区间查询,将n当成l,m当成r即可.此题需要注意,对于求组合数得用o(1)的方法求,也就是阶乘相除的方法,对于分母我们得求逆元,因而借助欧拉定理. 代码实现如下: #include <set> #include &…
http://acm.hdu.edu.cn/showproblem.php?pid=6333 莫队算法是一个离线区间分块瞎搞算法,只要满足:1.离线  2.可以O(1)从区间(L,R)更新到(L±1,R±1)就能直接套板子了 这道题不是区间算法,但是有递推式: 把它看成区间更新orz 所以可以莫队orz #define _CRT_SECURE_NO_WARNINGS #include <cmath> #include <iostream> #include <stdio.h&…
Problem Description There are n apples on a tree, numbered from 1 to n.Count the number of ways to pick at most m apples.   Input The first line of the input contains an integer T (1≤T≤105) denoting the number of test cases.Each test case consists of…