CSP2025 题解
暴力:
二进制枚举子集
复杂度 $ n*2^n$
n==20时, \(20* 2^{20}=2*10^7\) 可以得40分啊
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int n, a[N], ans;
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
int ALL=(1<<n)-1;// ALL 就是二进制表示的全集
for(int i=0;i<=ALL;i++)
{
int cnt=0, maxv=-1e9, total=0;
for(int j=0;j<n;j++)
{
if((i>>j)&1)
{
cnt++;
total+=a[j];
maxv=max(maxv,a[j]);
}
}
if(cnt>=3 && total>2*maxv)
{
ans++;
}
}
cout << ans << endl;
return 0;
}
//11:25 完成
//暴力,估计40分
完美解答,看下面这个网站中的第四题:
CSP-J题解
https://mp.weixin.qq.com/s/vVy9N7VA2F8h0drZZkiVbg
CSP-S题解
https://mp.weixin.qq.com/s/oWowzGJnVeZiEkbnwKxMHw
心得
J组 T4
01 背包计数,还有正难则反的思维很重要。
可以做做下面这题回顾一下背包问题求方案数:
https://www.acwing.com/problem/content/11/
https://www.bilibili.com/video/BV1oK411b7je
https://www.bilibili.com/video/BV16K411A7iC
S组 T2
部分分分析很重要,如果全部分类写出,可以得60分,虽没想出最后正解,但也很高了
想得到满分,就要注意到n比m小, k<=10, 也很小。这两个就是瓶颈。

浙公网安备 33010602011771号