省选模拟 19/09/13
Posted qq62c30ac77b2a7
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了省选模拟 19/09/13相关的知识,希望对你有一定的参考价值。
组合数问题 很明显最下面的中间最大
把它放进堆,然后每次取最大,将它左右上分别放进堆中就可以了
现在的难题转换为求大小
一个套路就取 乘法转加法
#include<bits/stdc++.h>
#define N 1000050
using namespace std;
typedef long long ll;
const int Mod = 1000000007;
int read()
int cnt = 0, f = 1; char ch = 0;
while(!isdigit(ch)) ch = getchar(); if(ch == -) f = -1;
while(isdigit(ch)) cnt = cnt*10 + (ch-0), ch = getchar();
return cnt * f;
int n, k;
ll fac[N], ifac[N], a[N];
bool cmp(ll a, ll b) return a > b;
ll mul(ll a, ll b) return (a * b) % Mod;
ll add(ll a, ll b) return (a + b) % Mod;
ll power(ll a, ll b) ll ans = 1;
for(;b;b>>=1) if(b&1) ans = mul(ans, a); a = mul(a, a);
return ans;
ll C(int n, int m) return mul(fac[n], mul(ifac[n-m], ifac[m]));
typedef long double ld;
ld sum[N];
map<pair<int,int>, int> vis;
#define mp make_pair
struct Node
int x, y;
friend bool operator < (const Node &a, const Node &b)
return sum[a.x] + sum[b.y] + sum[b.x - b.y] < sum[b.x] + sum[a.y] + sum[a.x - a.y];
b[N];
priority_queue<Node> q;
int main()
n = read(), k = read();
fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
for(int i = 2; i <= n; i++) fac[i] = mul(fac[i-1], i);
ifac[n] = power(fac[n], Mod-2);
for(int i = n-1; i >= 2; i--) ifac[i] = mul(ifac[i+1], i+1);
sum[0] = sum[1] = log(1);
for(int i = 2; i <= n; i++) sum[i] = sum[i-1] + log(i);
ll ans = 0; int cnt = 0;
q.push((Node)n, n/2);
while(cnt < k)
Node now = q.top(); q.pop();
if(vis[mp(now.x, now.y)]) continue;
vis[mp(now.x, now.y)] = 1;
ans = add(ans, C(now.x, now.y));
++cnt;
q.push((Node)now.x - 1, now.y);
q.push((Node)now.x, now.y - 1);
q.push((Node)now.x, now.y + 1);
cout << ans; return 0;
字符串 首先有个暴力的莫队做法,就是先建好 ,然后每次插入删除字符串可以看做树上的链加
复杂度
注意到,于是可以把所有字符串拼在一起然后莫队,中途需要用以上是关于省选模拟 19/09/13的主要内容,如果未能解决你的问题,请参考以下文章