版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/V5ZSQ/article/details/82917458
Description
一共有 个数,第 个数是 , 可以取 中任意的一个值。 设 ,求 种类数。
Input
第一行一个数
。
然后
行,每行两个数表示
。
Output
输出一行一个数表示答案。
Sample Input
5
1 2
2 3
3 4
4 5
5 6
Sample Output
26
扫描二维码关注公众号,回复:
3494480 查看本文章
Solution
背包,背包体积 ,时间复杂度 ,用 优化一下复杂度为
Code
#include<cstdio>
#include<bitset>
using namespace std;
bitset<1000005>b[105];
int n,l[105],r[105];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d%d",&l[i],&r[i]);
b[0].set(0);
for(int i=1;i<=n;i++)
for(int j=l[i];j<=r[i];j++)
b[i]|=(b[i-1]<<(j*j));
printf("%d\n",b[n].count());
return 0;
}