uva 11609 Teams
2016-08-03 00:17
302 查看
原题:
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 ≤ 10 9 ), 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(0,n)+1×C(1,n)+2×C(2,n)+….+n×C(n,n)
如果记得这个公式的最后结果可以直接写出来等于n×2^(n-1)
如果不记得,可以直接把组合数展开,然后把n提出来后能够得到结果
或者利用K×C(K,n)=n×C(K-1,n-1)的公式替换。
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 ≤ 10 9 ), 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
#include <bits/stdc++.h> using namespace std; const long mod=1000000007; long quickmod(long a,long b) { long ans=1; while(b) { if(b&1) { ans=(ans*a)%mod; b--; } b/=2; a=a*a%mod; } return ans; } int main() { ios::sync_with_stdio(false); long n,t,k=1; cin>>t; while(t--) { cin>>n; long ans=(n%mod)*(quickmod(2,n-1)%mod)%mod; cout<<"Case #"<<k++<<": "<<ans<<endl; } return 0; }
解答:
非常简答的数学题,公式能够很容易的就列出来等于
0×C(0,n)+1×C(1,n)+2×C(2,n)+….+n×C(n,n)
如果记得这个公式的最后结果可以直接写出来等于n×2^(n-1)
如果不记得,可以直接把组合数展开,然后把n提出来后能够得到结果
或者利用K×C(K,n)=n×C(K-1,n-1)的公式替换。
相关文章推荐
- 后台开发基础
- 汉字取首字母
- win10笔记本电脑双显卡亮度不能调节
- 优雅地实现Android Toolbar及沉浸式状态栏(二)
- location alias与root
- gitlab安装 vmware ubuntu16 linux 虚拟机 dns无法解析
- AsyncTask异步从网上下载图片
- js笔记整理02
- 大数据IMF传奇行动绝密课程第20课:Top N彻底解秘
- [BZOJ4513] [SDOI2016] 储能表 - 数位DP
- 树的直径学习总结
- ace在linux下编译
- am命令启动Acitivity流程图
- 陶伯定理(Tauber theorem)
- python_django 返回和 通用视图
- Retrofit2 完全解析 探索与okhttp之间的关系
- 关于水平居中,垂直居中的三种办法
- 【一步一步学习VBA】VBA获取单元格数值并弹窗显示
- 网站从http过度到https需要注意的几个小问题
- iBATIS入门之安装配置与简单测试