UVA 11609 - Teams(二项式系数)
想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数。
选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的。。。
搜了一下题解,先选队长Cn1,选一个人的时候Cn-1 0,选2个人的时候Cn-1 1这样就构成二项式系数了。
一约,n*2^n-1。。。最后,还忘了取模,错了好多次。。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
#define LL long long
#define MOD 1000000007
LL fastmod(LL a,LL k)
{
LL b = ;
while(k)
{
if(k&)
b = a*b%MOD;
a = (a%MOD)*(a%MOD)%MOD;
k = k/;
}
return b;
}
int main()
{
LL n,t,cas = ;
cin>>t;
while(t--)
{
cin>>n;
cout<<"Case #"<<cas++<<": ";
cout<<(n*fastmod(,n-))%MOD<<endl;
}
return ;
}
UVA 11609 - Teams(二项式系数)的更多相关文章
- UVA 11609 Teams 组合数学+快速幂
In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...
- UVA - 11609 Teams (排列组合数公式)
In a galaxy far far awaythere is an ancient game played among the planets. The specialty of the game ...
- Uva 11609 Teams (组合数学)
题意:有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案. 思路:我们首先C(n,1)选出一人当队长,然后剩下的 n-1 人组合的总数为2^(n-1),这里用快速幂解决 代码: #in ...
- UVA 11609 - Teams 组合、快速幂取模
看题传送门 题目大意: 有n个人,选一个或者多个人参加比赛,其中一名当队长,如果参赛者相同,队长不同,也算一种方案.求一共有多少种方案. 思路: 排列组合问题. 先选队长有C(n , 1)种 然后从n ...
- UVa 11609 (计数 公式推导) Teams
n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...
- Teams UVA - 11609
题意就不多说了这个小规律不算难,比较容易发现,就是让你求一个数n*2^(n-1):很好想只是代码实现起来还是有点小困(简)难(单)滴啦,一个快速幂就OK了: 代码: #include<stdio ...
- Teams UVA - 11609(快速幂板题)
写的话就是排列组合...但能化简...ΣC(n,i)*C(i,1) 化简为n*2^(n-1) ; #include <iostream> #include <cstdio> # ...
- uva - 10833 Supermean(二项式系数,对指数)
模拟发现,每个元素求和时,元素的系数是二项式系数,于是ans=sum(C(n-1,i)*a[i]/2^(n-1)),但是n太大,直接求会溢出,其实double的范围还是挺大的,所以可以将组合数转化成对 ...
- uva 11609
可以想到 答案为 1*C(1,n)+2*C(2,n)+3*C(3,n)+....+n*C(n,n); 由公式 k*C(k,n) = n*C(k-1,n-1) 所以最终答案 n*2^(n-1) 用到快速 ...
随机推荐
- Pyqt 获取windows系统中已安装软件列表
开始之前的基础知识 1. 获取软件列表 在Python的标准库中,_winreg可以操作Windows的注册表.获取已经安装的软件列表一般是读去windows的注册表: SOFTWARE\Micros ...
- 【翻译六】java-连接和实例
Joins The join method allows one thread to wait for the completion of another. If t is a Thread obje ...
- SQL分组和聚合(Grouping and Aggregates)
这章应该是难点,也是成为SQL高手的必经之路. 注意有GROUP 语句时,WHERE和HAVING的场合. 前者用于检索前的条件过滤 . 后者用于检索出来结果之后的条件过滤. ========== ; ...
- go sample-base64
GoSample-base64 package mainimport ( "encoding/base64" "fmt")func base64Encode(s ...
- 【leetcode】Remove Duplicates from Sorted Array
题目描述: Given a sorted array, remove the duplicates in place such that each element appear only once a ...
- hdu 4025 2011上海赛区网络赛E 压缩 ***
直接T了,居然可以这么剪枝 题解链接:点我 #include<cstdio> #include<map> #include<cstring> #define ll ...
- 传引用 C(转)
转自:http://myturn.blog.hexun.com/15584978_d.html #include <iostream> using namespace std ; void ...
- OVER(PARTITION BY)函数用法
OVER(PARTITION BY)函数介绍 开窗函数 Oracle从8.1.6开始提供分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返 ...
- php 常见的问题
1. this指针错误的引用变量($(php)<->*(c)) $this->inputData right wrong 2. json_encode(array) 不一定按数组关键 ...
- maven会报Could not transfer artifact xxx错误
需要在你的eclipse更新一下maven的包 如下: