码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-19 11:03:34      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   os   io   strong   for   ar   

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

 

 

 

bubuko.com,布布扣

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 (排列组合数公式),布布扣,bubuko.com

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

标签:style   blog   http   os   io   strong   for   ar   

原文地址:http://blog.csdn.net/u011345136/article/details/38677253

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!