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防止溢出;用%I64d竟然PE(⊙_⊙)。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

long long N,MOD = 1000000007;

long long spow( long long x, long long n )
{
	if ( n == 0LL ) return 1LL;
	if ( n == 1LL ) return x%MOD;
	long long v = spow( x, n/2LL );
	if ( n%2LL == 1LL )
		return ((v*v)%MOD*x)%MOD;
	else return (v*v)%MOD;
}

int main()
{
	int T;
	while ( cin >> T )
	for ( int t = 1 ; t <= T ; ++ t ) {
		cin >> N;
		printf("Case #%d: %lld\n",t,spow(2LL,N-1LL)*N%MOD);
	}
	return 0;
}

UVa 11609 - Teams

时间: 2024-11-08 17:12:26

UVa 11609 - Teams的相关文章

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 som

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 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

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

Teams UVA - 11609

题意就不多说了这个小规律不算难,比较容易发现,就是让你求一个数n*2^(n-1):很好想只是代码实现起来还是有点小困(简)难(单)滴啦,一个快速幂就OK了: 代码: #include<stdio.h> #define mod 1000000007 #define ll long long ll pow(ll a,ll b) { ll ans=1; while(b) { if(b%2>0) ans=ans*a%mod; a=a*a%mod; b/=2; } return ans; } in

Teams UVA - 11609(快速幂板题)

写的话就是排列组合...但能化简...Σ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

UVa 11609 组队(快速幂)

https://vjudge.net/problem/UVA-11609 题意: 有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案. 思路: 之后就是快速幂处理. 1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<vector> 6 #include&

uva 11609

---恢复内容开始--- 题意: 给出n代表有n组测试数据,每组数据给出总人数,取任意人数组成小队,小队的任意成员都可以成为队长.问能组成几种不同的小队.注:当小队队员相同但队长不同时,算新的小队. Sample Input 3 1 2 3 Sample Output Case #1: 1 Case #2: 4 Case #3: 12 分析: 很简单的数学问题,用c(i,n)代表从n个人中取i个组成小队的取费,之后再乘i.这样就算出i个人能在组成小队的个数. 代码: #include<iostr