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 ...
随机推荐
- 【转载】#273 - Parameter Modifier Summary
Here's a summary of the different parameter modifiers and how the behavior changes for each, when us ...
- 洛谷 P3368 【模板】树状数组 2
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...
- 《服务器的追踪与审计》RHEL6
在linux系统/etc目录下有两个文件: 服务器的追踪: 当其他人访问我的主机时,通过日志监控到那台主机什么时间通过什么方式登陆,做什么?
- 4.Servlet_Form表单处理
1.建项目"3Servlet_Form",src下建包“com.amaker.servlet”,web-root下建Register.html <!DOCTYPE html& ...
- 学习CentOS7笔记(一)
说明: 1.这是我第一次接触CentOS7,从基础学起. 2.最终目的是为了在CentOS上面部ngix+php+mysql+naxsi环境,进行安全测试. 第一部分 认识CentOS 7 有时候我在 ...
- Xcode中为代码添加特殊标记
有时候,我们需要在代码中搜索特殊的符号或者代码段,根据符号或使用搜索功能导航代码段效率并不算高.为了使用普通的英语标识重要的代码片段,可在代码中插入特殊格式的注释.这些注释不会在应用程序中添加任何特殊 ...
- javascript框架库API入口
underscorejs : http://learning.github.io/underscore/
- 【Qt】QSettings介绍【转】
简介 QSettings类提供了持久的跨平台应用程序设置. 用户通常期望应用程序记住它的设置(窗口大小.位置等)所有会话.这些信息通常存储在Windows系统注册表,OS X和iOS的属性列表文件中. ...
- CSS3 text-rendering属性
这种非标准的属性目前不被推荐.我们一般会找一个可以替代的方法来完成相同的功能,不到外不得已,最好别用. CSS的这个text-rendering属性通常被用在Windows和Linux系统中,用来 ...
- rinetd 安装使用
1 下载解压: wget http://www.boutell.com/rinetd/http/rinetd.tar.gz tar zxvf rinetd.tar.gz 2 手动建立目录 mkdir ...