【洛谷P2915】Mixed Up Cows】的更多相关文章

[POJ3621][洛谷2868]Sightseeing Cows(分数规划) 题面 Vjudge 洛谷 大意: 在有向图图中选出一个环,使得这个环的点权\(/\)边权最大 题解 分数规划 二分答案之后把每条边的边权换为\(mid·\)边权-出点的点权 然后检查有没有负环就行啦 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath&g…
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题意: 给定一个长\(N\)的序列,求满足任意两个相邻元素之间的绝对值之差不超过\(K\)的这个序列的排列有多少个? 范围: \(0<=n<=16,0<=序列元素<=25000,0<=k<=3400\) 统计次数一般是递推干的事情,但是我们发现,这个递推并没有一个很明显的顺序关系,并不可以说前几个转移到下一个之类的. 看看数据这么小,一般都是状压干的事情了. 我们可以按照规模进行递推,即一个大小…
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large le…
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large le…
类似于n皇后的思想,只要把dfs表示放置情况的数字压缩成一个整数,就能实现记忆化搜索了. 一些有关集合的操作: {i}在集合S内:S&(1<<i)==1: 将{i}加入集合S:S=S|(1<<i): 集合S内包含了{0,1,2,...,n-2,n-1}:S==(1<<n)-1: #include <cstdio> #include <cstring> #include <cmath> using namespace std;…
传送门 状压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<<…
考场上空间开大了一倍就爆0了QAQ- Code: #include<cstdio> #include<algorithm> #include<cmath> using namespace std; const int maxn = 21; int height[30], pos[30]; long long dp[1 << maxn][21]; int main() { int n, delta; scanf("%d%d",&n,…
题目大意:给定一个长度为 N 的序列,每个位置有一个权值,现要求重新排列这个序列,使得相邻的权值差的绝对值大于 K,求合法排列的方案数. 题解: 由于 N 很小,应该可以想到状压,考虑如何进行设计状态.首先肯定要一个集合 S,其中第 i 项为 0 表示未被加入当前集合中,1 表示加入了当前的集合中.发现大的集合的方案数一定是由小的集合的方案数构成的,因此集合应该作为 dp 的阶段,还需要增加的维度是集合中元素组成的序列的最后一个值是多少.转移只需要枚举一个不在集合中且符合要求的点即可.时间复杂度…
P3047 [USACO12FEB]附近的牛Nearby Cows 题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into account, he wants to plant enough grass in each of his fields not only for the cows situated initially in that field, but…
题目大意:给定一个 N 个点,M 条边的有向图,点有点权,边有边权,求该有向图中的一个环,使得环上点权和与环上边权和之比最大. 题解:0/1 分数规划思想,每次二分一个 mid,在新图上跑 spfa,将问题转化成是否存在负环即可. 代码如下 #include <bits/stdc++.h> using namespace std; const int maxn=1010; const double eps=1e-4; struct node{int to;double w;}; vector&…