2025.2
2025.2
1. CF1091F - New Year and the Mallard Expedition
https://www.luogu.com.cn/problem/CF1091F
显然答案为所有
发现 sg 式子十分公式,形如
- 更新,则令
p[sg_k] |= k << ok;
- 查询,只用查询所有
的第 位即可。
复杂度
点击查看代码
// Problem: H. New Year and the Tricolore Recreation // Contest: Codeforces - Good Bye 2018 // URL: https://codeforces.com/problemset/problem/1091/H // Memory Limit: 256 MB // Time Limit: 4000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 10; int mx; int n, b, f[N]; int p[N], v[N], pc, isp[N]; bitset<N> ok, sg[70]; int main(){ mx = N - 10; for(int i = 2; i <= mx; ++ i){ if(!v[i]){ p[++pc] = i; isp[i] = 1; ok.set(i); } for(int j = 1; j <= pc && i * p[j] <= mx; ++ j){ v[i*p[j]] = 1; if(i % p[j] == 0){ break; } } } for(int i = 1; i <= pc; ++ i){ for(int j = 1; j <= pc && p[i] * p[j] <= mx; ++ j){ ok.set(p[i]*p[j]); } } scanf("%d%d", &n, &b); ok.set(b, 0); for(int i = 0; i <= mx; ++ i){ int val = 0; for(int j = 0; j < 70; ++ j){ if(!sg[j].test(i)){ val = j; break; } } f[i] = val; sg[val] |= ok << i; } int ans = 0; while(n--){ int a, b, c; scanf("%d%d%d", &a, &b, &c); ans ^= f[b-a-1] ^ f[c-b-1]; } puts(ans ? "Alice\nBob" : "Bob\nAlice"); return 0; }
2. qoj4228 - Double Sort
https://qoj.ac/contest/943/problem/4228
不考虑这个输出小数。来点
原题意可以转化为:对于所有
其中
如何计算这个
根据定义有:
根据二项式反演有:
根据插版法有:
求
最后一步可以在杨惠三角上直接证明。
带入,得:
由于
3. LuoguP4707 - 重返现世
https://www.luogu.com.cn/problem/P4707
一直想写这个题,今天写一下,发现写起来很简单。
首先要知道扩展 min-max 容斥式子:
题面求的是第
容易列出 dp:设
考虑利用上
那么新的 dp 状态就是:设
,表示 放入,但是不选;要求 (即不是第一个数); ,表示 放入且选;要求 (显然)。
初值
点击查看代码
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll P = 998244353; int f[10010][13]; int n, k, m, p[1010]; ll qp(ll x, ll y){ ll ans = 1; while(y){ if(y & 1){ ans = ans * x % P; } x = x * x % P; y >>= 1; } return ans; } int main(){ f[0][0] = 1; scanf("%d%d%d", &n, &k, &m); k = n - k + 1; for(int i = 1; i <= n; ++ i){ scanf("%d", &p[i]); for(int v = m; v >= p[i]; -- v){ for(int c = 0; c <= k; ++ c){ if(c){ f[v][c] -= f[v-p[i]][c-1]; if(f[v][c] < 0){ f[v][c] += P; } } if(v > p[i]){ f[v][c] -= f[v-p[i]][c]; if(f[v][c] < 0){ f[v][c] += P; } } } } } ll ans = 0; for(int i = 1; i <= m; ++ i){ ans += qp(i, P-2) % P * f[i][k] % P; ans %= P; } printf("%lld\n", ans * qp(P-1, k) % P * m % P); return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步