UVA-11609 Teams
来源:互联网 发布:加工中心打孔编程 编辑:程序博客网 时间:2024/06/06 13:10
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
分析:根据组合数的性质,0*C(n,0)+1*C(n,1)+……+n*C(n,n)=n*2^(n-1)。2*10^9较大,应使用快速幂,否则会超时。快速幂就是折半求幂,将每一步的结果进行保存,避免重复求解。
Source:
#include<stdio.h>long long f(int n) //快速幂{ long long v; if(n==0) return 1; v=f(n/2); //将每一步结果保存在v中 if(n%2==0) return v*v%1000000007; else return (v*v%1000000007*2)%1000000007;}int main(){ int t,n,i; long long ans; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%d",&n); ans=(n*f(n-1))%1000000007; printf("Case #%d: %lld\n",i,ans); } return 0;}
- UVa:11609 Teams
- UVa 11609 - Teams
- uva 11609 - Teams
- UVA 11609 Teams
- Teams(UVA 11609)
- UVA 11609 Teams
- uva 11609Teams
- UVA-11609 Teams
- UVa 11609 Teams (组合数学)
- UVA-11609-Teams-组合计数
- UVa 11609 Teams (组合数学)
- UVA 11609 - Teams 组合、快速幂取模
- uva 11609 - Teams(组合数学+快速幂)
- UVA - 11609 Teams (排列组合数公式)
- UVa 11609 - Teams (组合数学)
- UVa 11609 Teams(快速幂+数学)
- UVa-11609 Teams(组合+快速幂)
- Uva 11609 - Teams 解题报告(组合数学)
- 安装shifter实践指南
- java安全架构____java Base64原理分析
- WordCount class not found 和 FileAlreadyExistsException,运行WordCount
- C++中数组的最大长度
- java中Collections.sort排序详解
- UVA-11609 Teams
- OWASP——简介及认识
- 人人都可以做深度学习应用:入门篇
- Codeforces Round #401 (Div. 2)A. Shell Game(水题~)
- 【Leetcode】350. Intersection of Two Arrays II
- gson使用
- Retrofit学习一:小试牛刀
- C++primer plus阅读笔记第四章
- 中文语料库and分词