题目链接:https://www.luogu.org/problemnew/show/P1879 状压DP. 设dp[i][j]表示第i行,状态为j的方案数 初始dp[0][0] = 1 这样一共12行12列,最多1<<12. 这样转移时,只要满足上下没有两个1,这两行分别满足没有相邻1. 加法原理转移. \(j&k==0\) $ dp[i][j] += dp[i-1][k] $ #include <cstdio> #include <cstring> #inc…
题目链接:https://www.luogu.org/problemnew/show/P3258 谁说树剖过不去会RE呢? 我今天就是要强行树剖了 树剖强艹 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long using namespace std; const int maxn = 500010; ll ans[…
题目链接:https://www.luogu.org/problemnew/show/P1606 这个题..第一问很好想,但是第二问,如果要跑最短路计数的话,零边权的花怎么办? 不如这样想,如果这个点能到花的话,那把他和从花能到的一个点边权连成一,好比两条路径共为1:一条为1一条为0的路径 但在实际操作的时候,一朵花是可以到另一朵花的! 电风扇好啊 #include <queue> #include <cstdio> #include <cstring> #includ…
题目链接:https://www.luogu.org/problemnew/show/P2936 菜 #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 10000; const int inf = 1e9; int n, m, s,…
题目链接:https://www.luogu.org/problemnew/show/P3128 菜 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long long #define lson left, mid, rt<<1 #define rson mid+1, right, rt<<1|1 usin…
题目链接:https://www.luogu.org/problemnew/show/P2860 考虑在无向图上缩点. 运用到边双.桥的知识. 缩点后统计度为1的点. 度为1是有一条路径,度为2是有两条路径. #include <stack> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; cons…
题目链接:https://www.luogu.org/problemnew/show/P2397 卡空间. 对于众数出现次数 > n/2 我们考虑rand. 每次正确的概率为1/2,五个测试点,全对的概率为1/32. 所以: #include <ctime> #include <cstdio> #include <cstdlib> using namespace std; int n, m; int main() { scanf("%d",&a…
题解报告:https://www.luogu.org/problemnew/show/P2341 我们把图中的强连通分量缩点,然后只有出度为0的牛是受欢迎的,这样如果出度为0的牛只有一个,说明受所有牛欢迎.否则出度为0只是受一些牛欢迎. #include <stack> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using names…
题目链接:https://www.luogu.org/problemnew/show/P2939 本来说是双倍经验题,跟飞行路线一样的,结果我飞行路线拿deque优化SPFA过了这里过不了了. 所以多学一种优先队列优化. #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define ll long lon…
题目链接:https://www.luogu.org/problemnew/show/P4711 要细心模拟 #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <iostream> using namespace std; char s[10001]; int k; double nans1, nans2, fans, ffans…