跳到正文

个人记录

#515. 「LibreOJ β Round #2」贪心只能过样例 (bitset)

nofind约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月5日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

题意:https://loj.ac/problem/515

考虑O(N^2S)的暴力(S是最终答案的上界,为1e6),就是暴力可行性DP

用bitset优化一下即可

code:

C++
#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
const int maxm=1e6+10;
int n;
int a[maxn],b[maxn];
bitset<maxm>f[2];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		int now=i&1;
		f[now].reset();
		for(int j=a[i];j<=b[i];j++)f[now]|=(f[now^1]<<(j*j));
	}
	printf("%d",f[n&1].count());
	return 0;
}
原文