UVa 11609 (计数 公式推导) Teams】的更多相关文章

n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typedef long long LL; ; LL pow(int p) { LL ans = , ; while(p) { ) ans = (ans * base) % M; p >>= ; base = (base * base) % M; } return ans; } int main() { /…
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…
In a galaxy far far awaythere is an ancient game played among the planets. The specialty of the game isthat there is no limitation on the number of players in each team, as long asthere is a captain in the team. (The game is totally strategic, so som…
题目链接 想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数. 选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的... 搜了一下题解,先选队长Cn1,选一个人的时候Cn-1 0,选2个人的时候Cn-1 1这样就构成二项式系数了. 一约,n*2^n-1...最后,还忘了取模,错了好多次.. #include <cstdio> #include <cstring> #include <string> #include <…
题意:有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案. 思路:我们首先C(n,1)选出一人当队长,然后剩下的 n-1 人组合的总数为2^(n-1),这里用快速幂解决 代码: #include <iostream> #define ll long long using namespace std; ; ll qmod(ll a, ll b) { ll ans=; while(b) { ) { ans=(ans*a)%mod; } b=b/; a=(a*a)%mod; } re…
题意就不多说了这个小规律不算难,比较容易发现,就是让你求一个数n*2^(n-1):很好想只是代码实现起来还是有点小困(简)难(单)滴啦,一个快速幂就OK了: 代码: #include<stdio.h> #define mod 1000000007 #define ll long long ll pow(ll a,ll b) { ll ans=; while(b) { >) ans=ans*a%mod; a=a*a%mod; b/=; } return ans; } int main()…
写的话就是排列组合...但能化简...ΣC(n,i)*C(i,1) 化简为n*2^(n-1) ; #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queu…
看题传送门 题目大意: 有n个人,选一个或者多个人参加比赛,其中一名当队长,如果参赛者相同,队长不同,也算一种方案.求一共有多少种方案. 思路: 排列组合问题. 先选队长有C(n , 1)种 然后从n-1个人中选,但人数不确定,所以应是1个~n-1个人的和. 比如n=1,那么就是C(n , 1)种 n=2 那么就是 C(n , 1)  +  C(n ,1) * C(n-1 , 1) n=3那么就是 C(n , 1)  +  C(n ,1) * C(n-1 , 1)  +  C(n , 1) *…
题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以分块的时候要多分几种情况. 以2345为例,这是一个四位数,首先要计算一下所有的一位数.两位数以及三位数各个数字出现的个数. 对应的模板分别为n,n*,n**,其中n代表非零数字,*代表任意数字. 考虑这样一个长为l的模板****(l个*),这样的数共10l个,而且各个数字都是等频率出现,所以每个数…
题目链接:10911 - Forming Quiz Teams 题目大意:给出2 * n个选手的坐标, 要求将所有的选手分成n组, 每组两个人, 所有组的两个人之间的距离之和要最小, 输出最小值. 解题思路:网络赛的时候写过类似的题目, 只不过是选4个点做正方形,所以思路很明确,每次选取任意两个点配对,递归搜索,并记录下来.然后我不是用未运算来记录点的状态,而开了个数组,因为位运算用不熟. #include <stdio.h> #include <string.h> #includ…