uva11609
以三个人组队为例,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的更多相关文章
- Teams(uva11609+组合)
I - Teams Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit cid=7795 ...
- uva11609(组合数学,快速幂)
先选人,再从这些人里选一个队长,方案总数:C(i,1)*C(n,i)(其中i从1到n)的总和. 这个公式显然不能在时限内暴力算出来,需要变形和推导出更简单的来. 用到组合数里面这个公式:C(n,k)* ...
- 题解 UVa11609
题目大意 给定一个正整数 \(n\),请求出所有小于 \(n\) 人的团队如果选出一个人作为队长的不同的方案数(假定这些人两两不相同)对 \(10^9+7\)取模的结果. 分析 即求 \[\sum^n ...
- UVa 11609 组队(快速幂)
https://vjudge.net/problem/UVA-11609 题意: 有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案. 思路 ...
随机推荐
- ol3对地图上某些特定的经纬度进行标注
最终效果需要类似于这种 1.首先我们需要一个最基本的地图,这一步骤可以浏览该分类下的上一篇随笔. 2.ol3支持的文件格式有.geojson,我们需要将坐标制作成符合这种格式的样子才能被ol3识别并显 ...
- SVM学习笔记5-SMO
首先拿出最后要求解的问题:$\underset{\alpha}{min}W(\alpha)=\frac{1}{2} \sum_{i,j=1}^{n}y^{(i)}y^{(j)}\alpha_{i}\a ...
- SpringBoot 整合携程Apollo配置管理中心
携程官网对apollo的使用讲解了很多种方式的使用,但是感觉一些细节还是没讲全,特别是eureka配置中心地址的配置 这里对springboot整合apollo说一下 >SpringBoot启动 ...
- POJ 1904 King's Quest(强连通图)题解
题意:n个王子有自己喜欢的ki个公主,有n个公主,每个王子只能娶一个自己喜欢的公主且不能绿别的王子.现在给你一种王子娶公主的方案,并且保证这种方案是正确的.请你给出,每个王子能娶哪些公主,要求娶这些公 ...
- (转)Spring Cloud(一)
(二期)22.微服务框架spring cloud(一) [课程22]spirng c...简介.xmind54KB [课程22]spirng cl...架构.xmind0.5MB [课程22]负载均. ...
- Leetcode121-Best Time to Buy and Sell Stock I - Easy
I Say you have an array for which the ith element is the price of a given stock on day i. If you wer ...
- 传输SO10 (SO10 Transport)
传输SO10 (SO10 Transport) 方法一. 手工添加到请求里面,格式为: R3TR TEXT text object, name, ID, language 方法二.使用程序:R ...
- Ajax - 发送请求原理
1,什么是ajax? Asynchronous JavaScript and XML(当然现在xml已经由json代替): 主要是用于前后台的交互(表单提交已经被废弃): 使用场景:前台获取数据.表单 ...
- SQLServer代理新建或者编辑作业报错
SQLServer代理新建或者编辑作业的时候报错如下 错误信息: 标题: Microsoft SQL Server Management Studio------------------------- ...
- 【Mysql】key 、primary key 、unique key 与index区别
参考:https://blog.csdn.net/nanamasuda/article/details/52543177 总的来说,primary key .unique key 这些key建立的同时 ...