传送门 状压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=…
差不多是原题啊. 求最长链变成了最长链计数,其余没有变化. 这一次考试为了保险起见本蒟蒻还是写了上次没写的辅助数组. 代码: #include<bits/stdc++.h> #define N 50005 #define M 200005 #define mod 1000000007 #define ll long long using namespace std; inline int read(){ int ans=0; char ch=getchar(); while(!isdigit(…