动物园zoo 题目大意:https://www.lydsy.com/JudgeOnline/problem.php?id=1151 题解: 我们发现每个点只会往右延伸$5$个,这个数非常小. 再加上每个动物只有选和不选,很容易想到把每个点后面$5$个给状压到一起. 想到这里就好办了,随便弄个数组搞一搞就好. 代码: #include <bits/stdc++.h> #define N 50010 using namespace std; int n, c, f[N][35], bu[N][35…
传送门 状压dp好题啊. 可以发现这道题的状压只用压缩5位. f[i][j]表示当前在第i个位置状态为j的最优值. 显然可以由f[i-1]更新过来. 因此只用预处理在第i个位置状态为j时有多少个小朋友高兴就行了. 代码: #include<bits/stdc++.h> #define N 50005 using namespace std; int n,c,f[N][35],cal[N][35],las,ans=0; inline int read(){ int ans=0; char ch=…
思路:因为每个人最多只能看到五个动物,我们考虑将其状压,f[ i ][ s ] 表示到了第 i 个位置, i, i + 1, i + 2, i + 3, i + 4这四个动物的状态为s, 此时的最大值. 因为它是一个环,所以我们考虑枚举前4位,这样就能dp啦,dp[i][s] = max(dp[i - 1][(15 & s) << 1], dp[i - 1][(15 & s) << 1 | 1]) + val[i][s]; val[ i ]][ s ] 是预处理出来…
Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where th…
link 试题分析 发现每个小朋友最多只能看到$5$个动物所以考虑状压$dp$.我们定义$f(i,j)$为第$i$个位置从此往后$5$个人的最喜欢数量.所以只要预处理出对于每个点从后$5$个会让多少小朋友高兴即可 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; inline int read(){ ,ans=;char…