传送门 状压dp入门题. 按照题意建一个图. 要求的就是合法的链的总数. 直接f[i][j]f[i][j]f[i][j]表示当前状态为jjj,下一位要跟iii连起来的方案数. 然后从没被选并且跟iii连通的点转移就行了. 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=20; bool tran[N][N]; int n,K,up,s[N]; ll f[N][1<<…
题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has submitted (and passed, of c…
传送门 看到n的范围的时候吓了一跳,然后发现可以矩阵快速幂优化. 我们用类似于状压dp的方法构造(1(1(1<<m)∗(1m)*(1m)∗(1<<m)m)m)大小的矩阵. 然后用快速幂转移. 代码: #include<bits/stdc++.h> #define mod 1000000007 #define N 128 #define ll long long using namespace std; int T,up,n,m; struct Matrix{ ll va…