n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法。

所以答案就是

第一步的变形只要按照组合数公式展开把n提出来即可。

 #include <cstdio>

 typedef long long LL;
const LL M = ; LL pow(int p)
{
LL ans = , base = ;
while(p)
{
if(p & ) ans = (ans * base) % M;
p >>= ;
base = (base * base) % M;
}
return ans;
} int main()
{
//freopen("in.txt", "r", stdin);
int T;
scanf("%d", &T);
for(int kase = ; kase <= T; kase++)
{
int n;
scanf("%d", &n);
LL ans = pow(n-);
printf("Case #%d: %lld\n", kase, (ans * n) % M);
} return ;
}

代码君

UVa 11609 (计数 公式推导) Teams的更多相关文章

  1. UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...

  2. UVA - 11609 Teams (排列组合数公式)

    In a galaxy far far awaythere is an ancient game played among the planets. The specialty of the game ...

  3. UVA 11609 - Teams(二项式系数)

    题目链接 想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数. 选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的... 搜了一下题解,先选队长Cn1,选 ...

  4. Uva 11609 Teams (组合数学)

    题意:有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案. 思路:我们首先C(n,1)选出一人当队长,然后剩下的 n-1 人组合的总数为2^(n-1),这里用快速幂解决 代码: #in ...

  5. Teams UVA - 11609

    题意就不多说了这个小规律不算难,比较容易发现,就是让你求一个数n*2^(n-1):很好想只是代码实现起来还是有点小困(简)难(单)滴啦,一个快速幂就OK了: 代码: #include<stdio ...

  6. Teams UVA - 11609(快速幂板题)

    写的话就是排列组合...但能化简...ΣC(n,i)*C(i,1) 化简为n*2^(n-1) ; #include <iostream> #include <cstdio> # ...

  7. UVA 11609 - Teams 组合、快速幂取模

    看题传送门 题目大意: 有n个人,选一个或者多个人参加比赛,其中一名当队长,如果参赛者相同,队长不同,也算一种方案.求一共有多少种方案. 思路: 排列组合问题. 先选队长有C(n , 1)种 然后从n ...

  8. UVa 1640 (计数) The Counting Problem

    题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以 ...

  9. uva 10911 - Forming Quiz Teams(记忆化搜索)

    题目链接:10911 - Forming Quiz Teams 题目大意:给出2 * n个选手的坐标, 要求将所有的选手分成n组, 每组两个人, 所有组的两个人之间的距离之和要最小, 输出最小值. 解 ...

随机推荐

  1. Apache Spark探秘:三种分布式部署方式比较

    转自:链接地址: http://dongxicheng.org/framework-on-yarn/apache-spark-comparing-three-deploying-ways/     目 ...

  2. 一些牛逼的统计SQL

    SQL 1.查询连续2天,每天发帖大于等于2次的用户 SELECT USER_ID FROM ( SELECT USER_ID, DATEDIFF(CREATE_TIME, '1971-01-01') ...

  3. JAVA 获取系统环境变量

    分享代码: package com.base.entity; import java.io.Serializable; import java.util.Comparator; /** * 系统环境变 ...

  4. BZOJ3550: [ONTAK2010]Vacation

    3550: [ONTAK2010]Vacation Time Limit: 10 Sec  Memory Limit: 96 MBSubmit: 91  Solved: 71[Submit][Stat ...

  5. idea从vcs引入maven项目报错

    一.问题 用idea从cvs上check out的maven项目,打开后,发现依赖的jar包都有红色下划线.检查本地的maven库中有对应的包,那就是依赖有问题,idea没有在本地找到对应的包. 二. ...

  6. Error: The VPN client agent was unable to create the interprocess communication depot.

    当安装Cisco AnyConnect VPN Client出现The VPN client agent was unable to create the interprocess communica ...

  7. leetcode 4 : Median of Two Sorted Arrays 找出两个数组的中位数

    题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  8. [Unity菜鸟] Final IK

    由于本人英文较烂,边翻译用户手册边学习. 用户手册  IK Components Final IK 包含许多强大高速的IK组件 Aim  AimIK solver是一个对CCD算法(cyclic co ...

  9. QT进度条QProgressBar的练习(定制QProgressBar,单独成为一个控件)

    progressbar.h #ifndef PROGRESSBAR_H #define PROGRESSBAR_H #include <QProgressBar> class QStrin ...

  10. 82. Remove Duplicates from Sorted List II

    题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct  ...