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 ...
随机推荐
- AMQ学习笔记 - 18. 持久化的测试
概述 对持久化的有效性进行测试. 测试实例 测试实例 结果预测 持久化递送 重启ActiveMQ后,消息还在队列中 非持久化递送 重启ActiveMQ后,消息不在队列中 demo设计 jms-prod ...
- c 语言时间的输出和比较
time_t The most basic representation of a date and time is the type time_t. The value of a time_t va ...
- JavaScript写选项卡
方法一: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- 纯css3 开关按钮
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- [Guava源码分析] Preconditions 前置条件
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3874170.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...
- PHP 函数extension_loaded();
extension_loaded — 检查一个扩展是否已经加载 例如: <?php if (!extension_loaded('gd')) { if (!dl('gd.so')) { exit ...
- 开始ubuntu 14.04 的装X模式---终端模式下中文输入,听歌,上irc 开启framebuffer看电影 截图
先上图吧 卡卡的全是在tty1 下的操作,看电影,听歌,截图 ,看图 ,上irc 等等,相当适合在小白面前装屁! 需要安装的软件: 为了能正常显示中文:安装fbterm sudo apt-get i ...
- argularJS学习笔记-增删改
<!doctype html> <html lang="en" ng-app> <head> <meta charset="UT ...
- LoadRunner报26612错误的解决方案
LoadRunner压力测试时,一直会报12261错误,错误内容大概如下: Error -26612: HTTP Status-Code=500 (Internal Server Error) for ...
- python学习2——数据类型
1. python是强类型 动态类型的语言,动态类型表明它可以在声明变量的时候,不必指定数据类型,强类型规定了它不能容忍隐式类型转换 2. python中的不可变类型有:int,string,tupl ...