UVa11609

11609 Teams
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
3123
Sample Output
Case #1: 1
Case #2: 4
Case #3: 12

题意:
       有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案。

分析:
       不论谁当队长,情况都是等价的。假设第一个人当队长,剩下的n-1个人可选可不选,有2^(n-1)种选法,所以答案就是n*2^(n-1)。

 1 #include <cstdio>
 2 #include <cmath>
 3 #define LL long long
 4 const LL MOD = 1000000007;
 5 LL pow_mod(LL a,LL p,LL n){
 6     if(p == 0) return 1;
 7     LL ans = pow_mod(a,p / 2,n);
 8     ans = ans * ans % n;
 9     if(p % 2 == 1) ans = ans * a % n;
10     return ans;
11 }
12 int main(){
13     int T; scanf("%d",&T); int kase = 0;
14     while(T--){
15         int n; scanf("%d",&n);
16         printf("Case #%d: %lld\n",++kase,n * pow_mod(2,n - 1,MOD) % MOD);
17     }
18     return 0;
19 }

时间: 2024-08-19 00:00:33

UVa11609的相关文章

Teams(uva11609+组合)

I - Teams Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 11609 题意:有n个人,选多个人参加比赛,其中一个是队长,队长不同其他选手相同也算作不同的方案,.问你一共有多少种方案. 思路:自己才纸上稍微推理一下,n*2n-1%mod: 转载请注明出处:寻找&星空の孩子 题目链接:UVA 11609 也欢迎来我开的专题刷题.哈哈htt

UVA11609 - Teams(组合数学+快速幂)

题目链接 题意:从N个人中选出K个人为一只队伍(1 <= K <= N),每个队伍都要有一个队长,当队长不同时,所代表的队伍也不同,求一共可以选出多少只队伍. 思路:依题目可得ans = sum(i * C(i, n)),化简可得ans = n * sum(C(i, n - 1)) = n * 2 ^ (n - 1).之后用快速幂求解. 代码: #include <iostream> #include <cstdio> #include <cstring>

uva11609(组合数学,快速幂)

先选人,再从这些人里选一个队长,方案总数:C(i,1)*C(n,i)(其中i从1到n)的总和. 这个公式显然不能在时限内暴力算出来,需要变形和推导出更简单的来. 用到组合数里面这个公式:C(n,k)*C(k,r)=C(n,r)*C(n-r,k-r)(其中r<=k) 一变换以后就可以推出最后结果就是n*(2^n-1),n比较大,所以再用下快速幂就好了. 这里从实际模型出发解释一下这个组合数公式: 有n个球,从中选k个,再从k个里选r个做上标记,有多少选法? 一种思路就是先选k个在从k个里选r个,结

组队 UVa11609

1.题目描述:点击打开链接 2.解题思路:首先选择一个人当队长,有n种选法:对于每一个队长,剩下的可以有0,1,2,...n-1个人,一共有2^(n-1)种情况.答案就是n*2^(n-1). 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> #in

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

行业软件

Paraform.v3.0.rar PKPM2006年6月份结构.nrg PKPM使用说明文件.rar Polyworksv9.0forwindows.rar Pro_NC 三轴铣床加工秘籍.rar PTC ICEM DDN V3.404.L.rar ShipConstructor.2006v1.00.rar simpack8613.rar StruCAD10.1.rar T3v2005.1.rar TrafficWare.Simtraffic.v6.614.rar Virtuozo.NT.v3

Spt Olga v7.1(v6.3, V6.2) 全动态多相流模拟计算程序

Code V.v10.4.SP1 LightTools.v7.3 Stoner Pipeline Simulator v9.9.0(v9.7.2, v9.6, v9.5) (SPS)建立了鄯乌管道离线电子管道系统,借助Visual Basic(VB)程序开发语言,开发了具有与现场一致的SCADA系统操作界面,应用SPS软件与VB语言接口,建立了前台操作界面与后台电子管道之间的实时连接独家所有,功能完整,可远程测试.Synergee gas V4.52 储气田和集气井仿真建模和分析 Schlumb

Fluent Airpak v2.1.12 Windows 1CD(CFD 软件,能模拟流动、传热、和化学反应等物理现象).rar

moldex3d-r7.0.rarParaform.v3.0.rarPKPM2006年6月份结构.nrgPKPM使用说明文件.rarPolyworksv9.0forwindows.rarPro_NC 三轴铣床加工秘籍.rarPTC ICEM DDN V3.404.L.rarShipConstructor.2006v1.00.rarsimpack8613.rarStruCAD10.1.rarT3v2005.1.rarTrafficWare.Simtraffic.v6.614.rarVirtuozo

行业软件网

TrafficWare.Simtraffic.v6.614.rar Virtuozo.NT.v3.6.EN.rar xsteel.rar Zemax20050203.rar 理正岩土计算4.01(16模块).rar ######################################### 联系电话 Phone: 13978244459 QQ:5269150 QQ:5269150 QQ:5269150 Email: [email protected] MSN: [email protec