以三个人组队为例,3组合是:C(3,0)=1,3,3,1。还有队长的选择。有

1*0,3*1,3*2,1*3种。

组合数:            1      3        3        1

队长的选择:    0        1        2        3

原本选择数是1*0+3*1+3*2+1*3=12种。现在用另一种方法计算,观察到左右是对称的,因此1的数量,3的数量都是3个,就等于(2^3)*4/2=12种。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
typedef unsigned long long ull;
const lon SZ=,INF=0x7FFFFFFF,mod=; void init()
{ } void work()
{ } lon pow(lon x,lon n)
{
lon res=,ele=x;
for(;n;)
{
if(n&)
{
res=res*ele%mod;
}
ele=ele*ele%mod;
n/=;
}
return res;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
ull casenum;
cin>>casenum;
//cout<<casenum<<endl;
for(ull time=;time<=casenum;++time)
//for(ull time=1;cin>>n,n;++time)
{
init();
work();
lon n;
cin>>n;
lon res=pow(2LL,n-);
res=res%mod*(n)%mod;
res%=mod;
res+=mod;
res%=mod;
cout<<"Case #"<<time<<": "<<res<<endl;
}
return ;
}

uva11609的更多相关文章

  1. Teams(uva11609+组合)

    I - Teams Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit cid=7795 ...

  2. uva11609(组合数学,快速幂)

    先选人,再从这些人里选一个队长,方案总数:C(i,1)*C(n,i)(其中i从1到n)的总和. 这个公式显然不能在时限内暴力算出来,需要变形和推导出更简单的来. 用到组合数里面这个公式:C(n,k)* ...

  3. 题解 UVa11609

    题目大意 给定一个正整数 \(n\),请求出所有小于 \(n\) 人的团队如果选出一个人作为队长的不同的方案数(假定这些人两两不相同)对 \(10^9+7\)取模的结果. 分析 即求 \[\sum^n ...

  4. UVa 11609 组队(快速幂)

    https://vjudge.net/problem/UVA-11609 题意: 有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案. 思路 ...

随机推荐

  1. clnt_create: RPC: Program not registered

    原因:[root@nfs nfs]# systemctl start nfs-utils 解决方法:[root@nfs nfs]# systemctl start nfs

  2. python --- 19 判断对象所属,区分函数和对象, 反射

    一.判断对象所属 isinstance, type , issubclass 1.issubclass(x,y)    判断x是否是y 的子类 2.type(x)  精准返回x 的数据类型 3.isi ...

  3. c++map用法

    #include<iostream> #include<algorithm> #include<map> using namespace std; void fun ...

  4. Markdon 作图语法 CSDN

    插入甘特图 gantt dateFormat YYYY-MM-DD title Adding GANTT diagram functionality to mermaid section 现有任务 已 ...

  5. noip模拟【ping】

    70:很容易想到的是枚举每一个可能的答案来判断是否可行,取最优即可,贪心选择. 100:满足题目条件的这个距离是满足单调性的.如果x不行,那么大于x的距离都不行,二分答案. 学会运用二分,by ws_ ...

  6. 【做题】spoj4060 A game with probability——dp

    赛前做题时忽然发现自己概率博弈类dp很弱,心好慌.(获胜概率或最优解期望) 于是就做了这道题,续了特别久. 一开始列dp式子的时候就花了很长时间,首先搞错了两次,然后忘记了根据上一轮dp值直接确定选什 ...

  7. 用原型封装一个操作DOM的例子

    <script> // 一句话 在构造函数里面写属性 在原型里面写方法 function Elem(d){ this.even=document.getElementById(d); } ...

  8. vue的全局方法和局部方法

    var infiniteScroll = require('vue-infinite-scroll') 等价写法 import infiniteScroll from 'vue-infinite-sc ...

  9. linux lsof/netstat查看进程和端口号相关命令:

    本文为博主原创,未经允许不得转载: 在linux操作时,经常要查看运行的项目的进程和端口号,在这里总结了以下常用到的相关命令: 1.查看系统运行的java项目,并查看进程号 这个用到的命令为: ps ...

  10. Ubuntu14.04 clang3.8 Installation Guide

    Reference Installing clang 3.8 on Ubuntu 14.04.3. Ubuntu14.04 clang3.8 Installation Guide 1.add the ...