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 Nplayers 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个人。选一个或者多个人參加比赛。当中一名当队长,有多少种方案?假设參赛者全然同样,但队长不同,算作不同方案。

思路:非常easy得到sum=i=1nC[n][i]i ,      当中C[n][i]    表示组合数, 那么依据排列数公式我们得到C[n][i]i=nC[n1][i1]

那么结果就变成了sum=ni=1nC[n1][i1]        =   n2n1    高速幂取模

#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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值