zoukankan      html  css  js  c++  java
  • Codeforces Round #663 (Div. 2) C. Cyclic Permutations

     链接 :http://codeforces.com/contest/1391/problem/C

    题解 :一开始 脑残了去推组合数,然后忘了这个东西

      然后去网上找了线性推组合数的板子wa了 我吐了。 我纯NT

    其实一共N个数的排列,考虑N的位置,然后考虑两边的数,两边的数只要有一边不按升序或者降序排列就可以了 然后就是一堆组合数就行了

    #include<bits/stdc++.h>
    #define rep(i,a,n) for(int i=a;i<=n;++i)
    #define per(i,a,n) for(int i=n;i>=a;--i)
    #define pb push_back
    #define fi first
    #define se second
    #define io std::ios::sync_with_stdio(false)
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    const int P = 1e9+7, INF = 0x3f3f3f3f;
    
    ll gcd(ll a,ll b)
    {
        return b?gcd(b,a%b):a;
    }
    ll qpow(ll a,ll n)
    {
        ll r=1%P;
        for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;
        return r;
    }
    
    int main()
    {
         
          ll ans1=1;
           int n;
           cin>>n;
           for(int i=1;i<=n;i++) ans1*=i,ans1%=P;
           ans1=(ans1-qpow(2,n-1)+P)%P;
         cout<<ans1<<endl;
    }
  • 相关阅读:
    深入了解css的行高Line Height属性
    Kafka消息队列
    架构图
    清理肠道好方法
    维特根斯坦
    ES查询DSL大于小于写法
    python虚拟环境
    Dockerfile
    flask基本使用
    泛型类多个类型参数的定义
  • 原文地址:https://www.cnblogs.com/acmLLF/p/13469939.html
Copyright © 2011-2022 走看看