组合数学题

题意: 给定两个数n,k,共有2^n位选手进行2^k场淘汰赛,比赛方可以改变k场比赛的结果,要求最大化的最小值是多少。

思路:先看特殊情况当k>n时,比赛方可以控制最大序号的选手直接赢得比赛(因为每一位选手只进行k场比赛)因此ans=2^n。

由于越大的总是被安排的失败的次数越多,因此,k每增加一就是使得Ck+1,n的选手被改变比赛淘汰,即ans增加Ck+1,n因此,我们从k+1,枚举到n,计算最小值的减少过程,最后即是ans

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>//#define int ll
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 200010, M = 2 * N, B = N, MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int n, m, k;
ll fact[N], infact[N];ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll mod) {ll res = 1;while (b) {if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}inline void init() { fact[0] = infact[0] = 1;pre(i, 1, 100000) {fact[i] = fact[i - 1] * i % MOD;;infact[i] = infact[i - 1] * qmi(i, MOD - 2, MOD) % MOD;}
}ll C(int a, int b)
{return fact[b] * infact[a] % MOD * infact[b - a] % MOD;
}void slove()
{cin >> n >> k;ll ans = qmi(2, n, MOD);if (k >= n) { cout << qmi(2,n,MOD) << endl; return; }pre(i, k + 1, n)ans = ((ans - C(i, n) + MOD) % MOD);cout << ans << Endl;
}signed main()
{int _;//si(_);_ = 1;init();while (_--){slove();}return 0;
}

Codeforces div2 D. Madoka and The Corruption Scheme相关推荐

  1. CF1717D Madoka and The Corruption Scheme

    CF1717D Madoka and The Corruption Scheme Summary: 二项式.二进制路径.(逆元) Day 20220907 距离 CSPS 43Days 距离 NOIP ...

  2. codeforces div2 Not Assigning 题解

    codeforces div2 Not Assigning 题解 原题链接 /* 题意:构造一棵素数树.素数树定义如下: 这颗树中任意一条边 or 任意两条边 权重之和为素数,每条边的权重自己分配. ...

  3. codeforces div2 C. Ehab and a 2-operation task

    题目链接: http://codeforces.com/contest/1088/problem/C 题目大意,给你一个数组,数组中的数据不超过1e5,让你经过不超过n+1次的以下两个操作,变为是严格 ...

  4. 图论 ---- dijkstra变种dp Codeforces Div2 703 E. Paired Payment

    题目链接 题目大意: 无向图,但是一次一定要走两步,权值为两个边边权和的平方.求1到其他每个点的最短距离. n∈[1,1e5],m∈[1,min(2e5,n(n−1)2)],wi∈[1,50]n\in ...

  5. Codeforces div2 #499 B. Planning The Expedition 大水题

    已经是水到一定程度了QAQ- Code: #include<cstdio> #include<algorithm> #include<cstring> using ...

  6. 【CodeForces - 1647D】Madoka and the Best School in Russia(分类讨论,因数分解)

    题目链接 题意: 判断一个数nnn,能否有至少两种方法将其表示为 n=a1a2...akn=a_1a_2...a_kn=a1​a2​...ak​(k>=1k>=1k>=1),需要满足 ...

  7. Codeforces Round #818 (Div. 2)

    D Madoka and The Corruption Scheme 我们可以将所有的比赛看成有 2n2^n2n 个叶子节点的二叉树 问题转换为对每个非叶子结点规定左/右儿子赢,并规定叶子节点编号 使 ...

  8. 2022下半年一些有趣(bushi)的题目记录

    dp字符串匹配 Text Editor 组合数 D. Madoka and The Corruption Scheme dp字符串匹配 Text Editor 链接:https://codeforce ...

  9. bart使用方法_使用简单变压器的BART释义

    bart使用方法 介绍 (Introduction) BART is a denoising autoencoder for pretraining sequence-to-sequence mode ...

最新文章

  1. mysql表情符号变为_mysql Emoji表情字符集转换
  2. 你有一份云栖大会的IoT邀请函,请查收
  3. Git 使用的问题总结
  4. [Redux/Mobx] redux和flux的区别是什么?
  5. 大数据是应对安全形势的进攻武器
  6. 机器学习速成课程 | 练习 | Google Development——编程练习:稀疏数据和嵌套简介
  7. 2018-02-03-PY3下经典数据集iris的机器学习算法举例-零基础
  8. mysql 矩表_mysql表某相同值最近一次出现的间距
  9. Flex 与.net 进行通信可以通过Fluorine(fluorinefx),WebORB For .net,Socket
  10. 【转载】C#反射 获取程序集信息和通过类名创建类实例(转载)
  11. NotePad 常用设置
  12. weblogic控制台超时时间_WebLogic如何设置session超时时间
  13. laydate 在vue中使用_如何在vue-cli项目里用layer的layData日期组件(代码)
  14. 熟练操作mac系统只需十分钟(Mac新手必看)!!
  15. Duplicate zip entry
  16. 记一次阿里巴巴电话面试题
  17. 服务产品(商品)评论中的产品特征挖掘方法
  18. Python引号的用法
  19. WPF3D图片轮播效果
  20. 细数一次装修中遇到的几十个坑

热门文章

  1. 蓝绿部署、滚动部署、灰度发布、金丝雀发布
  2. Android自定义不需要焦点的TextView以实现跑马灯效果
  3. PHP单例模式的本质
  4. Mysql学习笔记(全)
  5. 怎样将github上的代码下载到本地并运行?
  6. 053试题 331/507/564/574/625/673 - restore datafile
  7. CVE-2014-0321漏洞成因分析
  8. 基于ZigBee和STM32的智能家居控制系统的设计与实现(三)
  9. ENVI中出现tif文件无法直接打开
  10. RS-485通信和ModBus详解