UVA - 11609 Teams (排列组合数公式)

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 sometimesless
player increases the chance to win). So the coaches who have a total of
N
players to play, selects K (1 ≤ K ≤ N) players and makeone of them as the captain for each phase of the game. Your task is simple,just find in how many ways a coach can select a team from his
N players.Remember that, teams with same players but having different captain areconsidered as different team.

 

Input

Thefirst line of input contains the number of test cases T ≤ 500.Then each of the next T lines contains the value of
N (1 ≤ N ≤10^9), the number of players the coach has.

Output

 

Foreach line of input output the case number, then the number of ways teams can beselected. You should output the result modulo 1000000007.

Forexact formatting, see the sample input and output.

 

Sample Input                                                                               Outputfor Sample Input


3

1

2

3


Case #1: 1

Case #2: 4

Case #3: 12

 

ProblemSetter: Towhidul Islam Talukdar

SpecialThanks: Md. Arifuzzaman Arif

题意:有n个人,选一个或者多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同方案。

思路:很容易得到sum=∑i=1nC[n][i]?i
,      其中C[n][i]   
表示组合数, 那么根据排列数公式我们得到C[n][i]?i=n?C[n?1][i?1]

那么结果就变成了sum=n?∑i=1nC[n?1][i?1]       
=  
n?2n?1   
快速幂取模

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;

ll pow_mod(ll x, ll y) {
	ll ans = 1;
	while (y > 0) {
		if (y & 1)
			ans = ans * x % mod;
		y >>= 1;
		x = x * x % mod;
	}
	return ans;
}

ll n;

int main() {
	int t, cas = 1;
	scanf("%d", &t);
	while (t--) {
		scanf("%lld", &n);
		printf("Case #%d: %lld\n", cas++, n*pow_mod(2ll, n-1) % mod);
	}
	return 0;
}

UVA - 11609 Teams (排列组合数公式)

时间: 2024-11-09 12:31:15

UVA - 11609 Teams (排列组合数公式)的相关文章

UVa 11609 - Teams

题目:n个人中取出k个人组成一个小组,并且其中有一名组长,问有多少种取法. 分析:分治.组合数学.F(n) = C(n,1)*1 + C(n,2)*2 + ... = sum(C(n,i)*i) 推导:C(n,i)*i=n*...*(i+1)/ [i*(i-1)*...*1] * i=n * [(n-1)*...*i]/ [i*...*1]=C(n-1,i)*n F(n)= n*sum(C(n-1,i))= n * 2^(n-1) 利用快速幂求解即可. 说明:使用long long防止溢出:用%

UVA 11609 Teams 组合数学+快速幂

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

Uva 11609 Teams (组合数学)

题意:有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案. 思路:我们首先C(n,1)选出一人当队长,然后剩下的 n-1 人组合的总数为2^(n-1),这里用快速幂解决 代码: #include <iostream> #define ll long long using namespace std; const ll mod = 1000000007; ll qmod(ll a, ll b) { ll ans=1; while(b) { if(b&1) { ans=(a

Uva 10943 - How do you add ?( 组合数公式 + 递推 )

Uva 10943 - How do you add ?( 组合数公式 + 递推 ) 题意:给定一个数N,分解韡k个数,问有多少种组合.数可以重复 (N<=100) 分析:通过组合数学将题目抽象为 N个相同的小球,放入k个不同的盒子中,且允许盒子为空然后就可以用隔板法------> ANS = C(N+M-1,M-1)隔板法--> BD然后再根据组合数的性质可以进行递推(这题数据范围比较小)----> C(A,B) = C(A-1,B) + C(A-1,B-1);预处理一遍之后即可

Uva 11609 - Team ( 组合数学 + 二项式性质 + 快速幂取模 )

Uva 11609 - Team ( 组合数学 + 二项式性质 + 快速幂取模 ) 题意: 有N个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案? (如果参赛者完全相同但是队长不同,也算是一种情况) [ 1<=n <= 10^9 ] 分析: 这题要用到组合式公式的性质 转化之后快速幂取模轻松搞定之 代码: //Uva 11609 - Team /* 组合数公式 + 二项式系数性质 + 快速幂 手动自己推 -> F[n] = C(n,1)*1 + C(n,2)*2 + C(n,n

hdu 1799 (循环多少次?)(排列组合公式)

循环多少次? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3051    Accepted Submission(s): 1117 Problem Description 我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如, 如果代码中出现 for(i=1;i<=n;i++) OP ; 那么做了n次OP运算

UVA 11609 - Anne&#39;s game cayley定理

Lily: “Chantarelle was part of my exotic phase.”Bu?y: “It’s nice. It’s a mushroom.”Lily: “It is? That’s really embarrassing.”Bu?y: “Well, it’s an exotic mushroom, if that’s any comfort.”Joss Whedon, "Anne".A little girl whose name is Anne Spetri

poj 2249 Binomial Showdown(组合数 公式优化)

//  组合数学,开始了-- 题目地址 : poj 2249 Binomial Showdown Description In how many ways can you choose k elements out of n elements, not taking order into account? Write a program to compute this number. Input The input will contain one or more test cases. Eac

杭电 2200 Eddy&#39;s AC难题 (排列组合 公式)用double来表示64位

Eddy's AC难题 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3710    Accepted Submission(s): 1741 Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于Ranklist中每个人的ac数量也有一定的研究,他在无聊时经常在纸上把Ranklist上每个人的