链接:https://www.nowcoder.com/acm/contest/132/C
一共有 n个数,第 i 个数是 xi
xi 可以取 [li , ri] 中任意的一个值。
设 ,求 S 种类数。
输入描述:
第一行一个数 n。 然后 n 行,每行两个数表示 li,ri。
输出描述:
输出一行一个数表示答案。
示例1
输入
5 1 2 2 3 3 4 4 5 5 6
输出
26
备注:
1 ≤ n , li , ri ≤ 100
get到新东西 STL里面的bitset
参考:https://www.cnblogs.com/RabbitHu/p/bitset.html
扫描二维码关注公众号,回复:
6148567 查看本文章
https://www.cnblogs.com/xingkongyihao/p/9308663.html
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#include<bitset>
using namespace std;
const int maxn = 1e6 + 5;
bitset<maxn>f, t;
int main()
{
int n, l, r;
cin >> n;
f[0] = 1;
for(int i = 1; i <= n; i++)
{
cin >> l >> r;
for(int j = l; j <= r; j++)
t |=(f<<j*j);
f = t;
t.reset();
}
cout << f.count() << endl;
return 0;
}