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

思路:非常easy得到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 (排列组合数公式)的更多相关文章

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

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

  2. UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...

  3. UVA 11609 - Teams(二项式系数)

    题目链接 想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数. 选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的... 搜了一下题解,先选队长Cn1,选 ...

  4. Uva 11609 Teams (组合数学)

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

  5. UVa 11609 (计数 公式推导) Teams

    n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...

  6. Java利用递归算法统计1-6的数组排列组合数

    Java利用递归算法统计1-6的数组排列组合数 1.设计源码 /** * @Title:ArrayCombination.java * @Package:com.you.data * @Descrip ...

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

    循环多少次? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  8. Irrelevant Elements UVA - 1635 二项式定理+组合数公式+素数筛+唯一分解定理

    /** 题目:Irrelevant Elements UVA - 1635 链接:https://vjudge.net/problem/UVA-1635 题意:給定n,m;題意抽象成(a+b)^(n- ...

  9. Teams UVA - 11609(快速幂板题)

    写的话就是排列组合...但能化简...ΣC(n,i)*C(i,1) 化简为n*2^(n-1) ; #include <iostream> #include <cstdio> # ...

随机推荐

  1. CSS种让border-bottom大道text-decoration一样的效果,甚至要比它的效果更理想一些!

    <p style="width:300px;line-height: 30px;margin:0 auto;text-indent: 24pt;word-break:break-all ...

  2. (C++)i++和++i,哪个效率高一些

    在看<程序员面试笔试宝典>时,发现了这样一个问题,书中只给出了++i的效率高一些,但并没有给出具体的解释和说明. 在网上找到下面的答案: 1.从高级层面上解释 ++i 是i=i+1,表达式 ...

  3. docker入门——构建镜像

    前面我们已经介绍了如何拉取已经构建好的带有定制内容的Docker镜像,那么如何构建自己的镜像呢? 构建Docker镜像有以下两种方法: 使用docker commit命令. 使用docker buil ...

  4. Web前端开发资源集锦

    前端开发已经成为当前炙手可热的技术之一.本周我们除了给大家带技术相关资讯,还有一些技术人员常用的网站.希望大家不要错过我们本周的内容.原文来自:极客标签 为神马说写程序是很艰难的 程序员 做一名优秀程 ...

  5. Java实现根据输入的日期以及天数,获取此日期之后的天数的工作日

    public static void main(String[] args) { List<String> list = new ArrayList<String>();//节 ...

  6. Linux 下搭建流媒体服务器

    http://blog.csdn.net/huangtaishuai/article/details/9836581 ----------------------------------------- ...

  7. 用Navicat Premium 操作MySQL数据库

    1. 用Navicat来查看MySQL数据库        打开Navicat Premium–>[连接]–>[MySQL]–>[连接名:新建数据库的名字,此处为“本地”]:[主机: ...

  8. python中的sort、sorted、reverse、reversed详解

    python语言中的列表排序方法有三个:reverse反转/倒序排序.sort正序排序.sorted可以获取排序后的列表.在更高级列表排序中,后两中方法还可以加入条件参数进行排序. reverse() ...

  9. 解决win10锁屏后无法进入桌面

    方法一: TAKEOWN /F "%SystemRoot%\System32\InputMethod\CHS\ChsIME.exe" icacls "%SystemRoo ...

  10. 【转】SQL2008的sa账户被禁用,其他账户无法连接的解决方法

    或者你还有其它的sysadmin权限的账号,你可以用此账号登录,重置SA密码. 但是在以下情况下,怎么办呢? 1. SA密码丢失或者SA账号被禁用. 2. 你进行了一些安全操作,把BuiltinAdm ...