https://loj.ac/problem/515
题意:给出n个区间,然后从这些区间中取一个数,然后求将取出的数的平方相加得到的数的种类数。
思路:因为n <100,所以得出的数最大为1e6,.所以将得到的数放在bitset中。复杂度O(n ^ 2 *1e6/32)。按道理复杂度有点大,但还是过了。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define clr(x,y) memset(x,y,sizeof x)
#define PI acos(-1.0)
#define ITER set<int>::iterator
const int Mod = 1e9 + 7;
const int maxn = 1e6 + 10;
bitset<maxn>B[2];
int main()
{
int n;
while( ~ scanf("%d",&n))
{
int l = 0,r = 1;B[0].reset();B[1].reset();B[0][0] = 1;
for(int i = 1; i <= n; i ++)
{
int x,y;scanf("%d%d",&x,&y);
B[r].reset();
for(int j = x; j <= y; j ++)
{
B[r] |= B[l] << (j * j);
}
swap(l,r);
}
printf("%d\n",B[l].count());
}
return 0;
}