zoukankan      html  css  js  c++  java
  • CF838D Airplane arrangement

    • 原题链接:CF838D
    • 感觉很妙的一道组合数学题

    (solution)

    • 考虑连链为环,开一个虚点(n+1),并连接无向边((1,n+1),(n,n+1)),于是原图变成了一个环
    • 注意到这样下来每个人任意选择位置,任意选择方向最终都会停留在环的一些位置上,我们把这些位置当作集合(S)
    • 那么方案不合法当且仅当(n + 1 in S)
    • 考虑这个环每个位置完全等价,所以所有(S)出现的概率都相等,于是有(frac{inom{n}{m}}{inom{n+1}{m}})的概率合法
    • 不考虑合法,总方案是(2 ^ m * (n + 1) ^ m)
    • 乘起来即可
      代码非常短
    #include<bits/stdc++.h>
    using namespace std;
    int read(){
    	char c = getchar();
    	int x = 0;
    	while(c < '0' || c > '9')	c = getchar();
    	while(c >= '0' && c <= '9')	x = x * 10 + c - 48,c = getchar();
    	return x;
    }
    const int mod = 1e9 + 7; 
    int qpow(int x,int y){
    	int ans = 1;
    	while(y){
    		if(y & 1)	ans = 1ll * ans * x % mod;
    		x = 1ll * x * x % mod;
    		y >>= 1;
    	}
    	return ans;
    }
    int main(){
    	int n = read(),m = read();
    	printf("%lld
    ",1ll * qpow(2,m) * qpow(n+1,m-1) % mod * (n - m + 1) % mod);
    	return 0;
    }
    
  • 相关阅读:
    Let和Const的使用
    Spring框架学习10——JDBC Template 实现数据库操作
    python 学习
    delphi
    mysql 客户端连接报错Illegal mix of collations for operation
    tnsping 不通
    orm总结
    other
    resultset 查询时返回多个相同值
    vlan 知识学习
  • 原文地址:https://www.cnblogs.com/y-dove/p/14736942.html
Copyright © 2011-2022 走看看