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)
用到快速幂取余
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 1010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; ll mymod(int n)
{
if(n == 0) return 1;
ll x = mymod(n/2);
ll ans = x*x%MOD;
if(n%2) ans = ans*2%MOD;
return ans;
} int main()
{
int n, t, ca = 1;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
ll ans = mymod(n-1);
printf("Case #%d: %lld\n", ca++, ans*n%MOD);
}
return 0;
}
uva 11609的更多相关文章
- UVA 11609 - Teams(二项式系数)
题目链接 想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数. 选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的... 搜了一下题解,先选队长Cn1,选 ...
- 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
n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...
- Uva 11609 Teams (组合数学)
题意:有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案. 思路:我们首先C(n,1)选出一人当队长,然后剩下的 n-1 人组合的总数为2^(n-1),这里用快速幂解决 代码: #in ...
- 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 - 11609 Teams (排列组合数公式)
In a galaxy far far awaythere is an ancient game played among the planets. The specialty of the game ...
- UVa 11609 组队(快速幂)
https://vjudge.net/problem/UVA-11609 题意: 有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案. 思路 ...
- UVA 11609 - Anne's game cayley定理
Lily: “Chantarelle was part of my exotic phase.”Buffy: “It’s nice. It’s a mushroom.”Lily: “It is? Tha ...
随机推荐
- MYSQL基础03(日期函数)
工作中对日期的处理是经常遇到的,需求可能多种多样,因此重点介绍. 1.获取当前日期 select NOW() -- 结果:2015-10-28 22:41:11 ),NOW() -- 结果 2015- ...
- redis setnx 分布式锁
private final String RedisLockKey = "RedLock"; private final long altTimeout = 1 * 60 * 60 ...
- bzoj 1132 POI2008 Tro
大水题=_=,可我想复杂了…… 很裸的暴力,就是加了个小优化…… 叉积求面积 :abs(xi*yj - yi*xj) 所以去掉绝对值,把 xi 和 xj 提出来就可以求和了 去绝对值加个极角排序,每次 ...
- Mysql 存储程序
#1存储过程create procedure greeting() BEGIN # 77 = 16 FOR username + 60 for hostname + 1 for '@' DECLARE ...
- HTML5-Video & Audio
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- jquery ready()的几种实现方法小结
几种jQuery的ready ()的写法. 1.最常用也是最标准的 $(document).ready(){ }); 2.是上面的简写: $(function(){ }) 很奇怪?为什么能 ...
- referenceerror wx is not defined 微信JsSdk开发
如果你和我一样遇到了“referenceerror wx is not defined”错误,很有可能是jweixin-1.0.0.js与你其它某js冲突. 解决办法: <script type ...
- php 伪静态 (url rewrite mod_rewrite 重写)
mod_rewrite是Apache的一个非常强大的功能,它可以实现伪静态页面.下面我详细说说它的使用方法!对初学者很有用的哦!1.检测Apache是否支持mod_rewrite通过php提供的php ...
- oracle创建用户,修改用户,删除用户等关于用户的
--直接修改底层表 USER$ 更换用户名 1.windows 平台下运行 cmd 2.sqlplus /nolog 3.SQL> conn SYSTEM/123@ORCL as sysdba ...
- 边界函数Bounding Function(成长函数的上界)
根据成长函数的定义,猜测 -->break point K restricts maximum possible mh(N) a lot for N>k bounding funct ...