E 简单瞎搞题
题目地址:
基本思路:
bitset优化dp,设记录的是到第个数时的所有可能情况的集合,那么比较容易得到转移方程: , 。
参考代码:
#pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; #define IO std::ios::sync_with_stdio(false) #define int long long #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) #define mset(s, _) memset(s, _, sizeof(s)) #define pb push_back #define pii pair <int, int> #define mp(a, b) make_pair(a, b) #define INF 0x3f3f3f3f inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); } return neg * x; } inline void print(int x) { if (x < 0) { putchar('-'); x = -x; } if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } int n; bitset<1000100> dp[110]; signed main() { IO; cin >> n; dp[0][0] = 1; rep(i,1,n){ int l,r; cin >> l >> r; rep(j,l,r) dp[i] |= (dp[i-1] << (j * j)); } cout << dp[n].count() << '\n'; return 0; }