In a galaxy far far away there is an ancient game played among the planets. The specialty of the game
is that there is no limitation on the number of players in each team, as long as there is a captain in
the team. (The game is totally strategic, so sometimes less 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 make one 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 are considered as different team.
Input
The first 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 ≤ 109
), the number of players the coach has.
Output
For each line of input output the case number, then the number of ways teams can be selected. You
should output the result modulo 1000000007.
For exact formatting, see the sample input and output.
Sample Input
3
1
2
3
Sample Output
Case #1: 1
Case #2: 4
Case #3: 12

题意:给你一个n,n个人,标号为1~n,现在选若干人组成一队,并且选出一个队长,问说可以选多少种队伍,队长,人数,成员不同均算不同的队伍。

题解:我们枚举选择k个人(1<=k<=n)

答案就是: 1*c(n,1)+2*c(n,2)+.......+n*c(n,n);

   接着提出n

    化为:    n*(c(n-1,0)+c(n-1,1)+c(n-1,2)+......+c(n-1,n-1));

  答案就是:n*(2^(n-1));快速幂求解

//meek///#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int inf = ;
const int MOD= ; ll quick_pow(ll x,ll p) {
if(!p) return ;
ll ans = quick_pow(x,p>>);
ans = ans*ans%MOD;
if(p & ) ans = ans*x%MOD;
return ans;
}
int main() {
int T,cas=;
ll n;
scanf("%d",&T);
while(T--) {
scanf("%lld",&n);
printf("Case #%d: %lld\n",cas++,n*quick_pow(,n-)%MOD);
}
return ;
}

DAIMA

    

UVA 11609 Teams 组合数学+快速幂的更多相关文章

  1. Uva 11609 Teams (组合数学)

    题意:有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案. 思路:我们首先C(n,1)选出一人当队长,然后剩下的 n-1 人组合的总数为2^(n-1),这里用快速幂解决 代码: #in ...

  2. UVa 11609 组队(快速幂)

    https://vjudge.net/problem/UVA-11609 题意: 有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案. 思路 ...

  3. UVA 11609 - Teams 组合、快速幂取模

    看题传送门 题目大意: 有n个人,选一个或者多个人参加比赛,其中一名当队长,如果参赛者相同,队长不同,也算一种方案.求一共有多少种方案. 思路: 排列组合问题. 先选队长有C(n , 1)种 然后从n ...

  4. hdu 5363 组合数学 快速幂

    Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 131072/131072 K (Java/Others) Problem Descrip ...

  5. codeforces 677C C. Vanya and Label(组合数学+快速幂)

    题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. BZOJ_1008_[HNOI2008]_越狱_(简单组合数学+快速幂)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1008 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰 ...

  7. Uva 10006 Carmichael Numbers (快速幂)

    题意:给你一个数,让你判断是否是非素数,同时a^n%n==a (其中 a 的范围为 2~n-1) 思路:先判断是不是非素数,然后利用快速幂对每个a进行判断 代码: #include <iostr ...

  8. UVa 10870 Recurrences (矩阵快速幂)

    题意:给定 d , n , m (1<=d<=15,1<=n<=2^31-1,1<=m<=46340).a1 , a2 ..... ad.f(1), f(2) .. ...

  9. ACM学习历程—SNNUOJ 1116 A Simple Problem(递推 && 逆元 && 组合数学 && 快速幂)(2015陕西省大学生程序设计竞赛K题)

    Description Assuming a finite – radius “ball” which is on an N dimension is cut with a “knife” of N- ...

随机推荐

  1. golang面向对象初识

    struct是变量的集合 interface是方法的集合 struct与interface都支持匿名字段, 换言之, 支持组合实现继承. golang的struct与C++的class一样, 只能声明 ...

  2. KnockoutJS学习笔记10:KonckoutJS foreach绑定

      KnockoutJS foreach绑定用来处理数组,通常用来将一个数组绑定到一个列表或者table中.在foreach绑定中,我们可以使用if.with等嵌套绑定. 示例代码: <tabl ...

  3. sql server 查询数据库所有的表名+字段

    SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Account' SELECT    (case when a.colorder= ...

  4. web relase

    http://wenku.baidu.com/link?url=uOAV9QwXGGLjeqt6M1KTqwp0Jbhhguvz9IxExCHNiUlrYMX584Io3ByNJJIkAVzEqzv9 ...

  5. Go字符串函数

    下面的代码中,列出了Go官方包中常见的字符串函数. package main import s "strings" import "fmt" //为打印函数起个 ...

  6. random_names随机名字生成

    // 先从txt文件中获取姓和名数组 - (void)getNames{ NSString *resourcePath1 = [[NSBundle mainBundle] pathForResourc ...

  7. Layout Support 获取上下bar的长度

    Layout Support This protocol . You can use layout guides as layout items in the NSLayoutConstraint f ...

  8. 57.DDR3的系统时钟编译错误

    错误:Xst:2033 - Port I of Input buffer ddr3_mig/memc3_infrastructure_inst/se_input_clk.u_ibufg_sys_clk ...

  9. Python实现CART(基尼指数)

    Python实现CART(基尼指数) 运行环境 Pyhton3 treePlotter模块(画图所需,不画图可不必) matplotlib(如果使用上面的模块必须) 计算过程 st=>start ...

  10. Kinect帮助文档翻译之三 多场景

    在多个Sense中使用KinectManager 为了在多个场景下都能使用KinectManager这个组件,它必须被附在一个只生成一次.不会被销毁且在所有场景中都能访问的游戏物体上,显然把它附在Ma ...